Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Code Samples for new v1p1beta1 features #118

Merged
merged 53 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b823117
MicrophoneStreamTest, and basic .ava tests-
Jun 8, 2018
53cd4f0
Just cosmetic, removed some notes, added note about Event style for t…
Jun 11, 2018
d13734f
removed .test, cleaned up yaaarghs
Jun 12, 2018
709638b
Cleaned up test within MicStream.js, .ava tests forthcoming
Jun 13, 2018
a27324c
Merge branch 'master' into master
JustinBeckwith Jun 13, 2018
6c452f7
Pruned down to core streaming function, yaargs rebuilt, .ava upcoming
Jun 14, 2018
b6add2d
Merge branch 'master' of https://github.com/CallistoCF/nodejs-speech
Jun 14, 2018
6f44c0c
newest .ava test, just makes sure yaargs loads, comments addressed
Jun 15, 2018
9e0bf4c
Added Readme
CallistoCF Jul 17, 2018
ad8007c
BetaFeatures for Test, fixed from yesterday
Jul 18, 2018
3e77731
Updated Readme
CallistoCF Jul 18, 2018
3504280
Updated Readme, fixed old paths used in testing
CallistoCF Jul 18, 2018
2974091
Updated Readme again
CallistoCF Jul 18, 2018
be3869f
Updated Yaargs Examples to fit readme
CallistoCF Jul 18, 2018
0fbba57
Fixed Diarization bug
Jul 19, 2018
554af87
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
Jul 19, 2018
0cad177
Merge branch 'master' into BetaFeatures
CallistoCF Jul 20, 2018
e0caf82
Merge branch 'master' of https://github.com/CallistoCF/nodejs-speech …
Jul 20, 2018
950844e
Speech Fixes
Jul 23, 2018
c365046
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
Jul 23, 2018
27b42dc
fixing eslint settings to merge
Jul 23, 2018
e583e2e
eslint again
Jul 23, 2018
c3840eb
testing lint quick fix
Jul 23, 2018
054e7f8
more ESlint shennanigans
Jul 23, 2018
b3174dd
cleaned up region tags
Jul 23, 2018
37ae0a6
Removed audiochannelGCS
Jul 23, 2018
3c5ae14
Removed Comments, also multiChannel GCS
CallistoCF Jul 24, 2018
da0736f
Removed Comments, GCS MultiChannel
CallistoCF Jul 24, 2018
44d6502
Removed multi Audio Channel
CallistoCF Jul 24, 2018
45418b2
Added mono-channel multi Language file to sample
CallistoCF Jul 24, 2018
6b793e0
removed old console.log
CallistoCF Jul 24, 2018
24cdc11
fixed todos and filename -> fileName
CallistoCF Jul 24, 2018
5487a88
removed docstrings
CallistoCF Jul 24, 2018
7852924
removed enableWordTimeOffsets in WordLvlConfidence
CallistoCF Jul 24, 2018
10bad72
rebuild
Jul 25, 2018
720f8fa
fixed space
Jul 25, 2018
3a18194
Merge branch 'master' into BetaFeatures
CallistoCF Jul 25, 2018
b6fee39
fixed package.lock for node8 circleCI
Jul 26, 2018
b0b0748
Attempted fix for circleCI node 8
Jul 26, 2018
701088b
attempted mime-types fix
Jul 26, 2018
0f4ea7a
possible mime/CLI fix
Jul 31, 2018
832b91d
Merged Latest package chore stuff, for circleCI
Jul 31, 2018
9e67988
Merge branch 'master' into BetaFeatures
JustinBeckwith Jul 31, 2018
e0f9d1d
all outstanding comments, except eslint issue
Jul 31, 2018
e95c8b3
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
Jul 31, 2018
cde3b24
confidence test fix
Jul 31, 2018
0331ea0
fixed eslinting in betaFeatures.js
Jul 31, 2018
0340b1e
eslint again
Jul 31, 2018
b024d2e
Fixed MultiChannel transcribe
Jul 31, 2018
f2d15c7
multiChannelGCS test
Jul 31, 2018
1808096
Updated readme
Jul 31, 2018
ed26504
updated readme, scaffolding
Jul 31, 2018
7cf0fa3
readme again
Jul 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ rules:
block-scoped-var: error
eqeqeq: error
no-warning-comments: warn
no-unsupported-features: off
205 changes: 98 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,148 +1,139 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Google Cloud Speech API: Node.js Client](https://github.com/googleapis/nodejs-speech)
# Google Cloud Speech API: Node.js Samples

[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-speech.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-speech)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/googleapis/nodejs-speech?branch=master&svg=true)](https://ci.appveyor.com/project/googleapis/nodejs-speech)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-speech/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-speech)

> Node.js idiomatic client for [Speech API][product-docs].
[![Open in Cloud Shell][shell_img]][shell_link]

The [Cloud Speech API](https://cloud.google.com/speech/docs) enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service.

## Table of Contents

* [Speech API Node.js Client API Reference][client-docs]
* [github.com/googleapis/nodejs-speech](https://github.com/googleapis/nodejs-speech)
* [Speech API Documentation][product-docs]

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].

[explained]: https://cloud.google.com/apis/docs/client-libraries-explained

**Table of contents:**

* [Quickstart](#quickstart)
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
* [Using the client library](#using-the-client-library)
* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Versioning](#versioning)
* [Contributing](#contributing)
* [License](#license)

## Quickstart
* [Speech Recognition](#speech-recognition)
* [Speech Recognition v1p1beta1](#speech-recognition-v1p1beta1)

### Before you begin
## Before you begin

1. Select or create a Cloud Platform project.
Before running the samples, make sure you've followed the steps in the
[Before you begin section](../README.md#before-you-begin) of the client
library's README.

[Go to the projects page][projects]
## Samples

1. Enable billing for your project.
### Speech Recognition

[Enable billing][billing]
View the [source code][recognize_0_code].

1. Enable the Google Cloud Speech API API.
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.js,samples/README.md)

[Enable the API][enable_api]
__Usage:__ `node recognize.js --help`

1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.
```
recognize.js <command>

Commands:
recognize.js sync <filename> Detects speech in a local audio file.
recognize.js sync-gcs <gcsUri> Detects speech in an audio file located in a Google Cloud Storage bucket.
recognize.js sync-words <filename> Detects speech in a local audio file with word time offset.
recognize.js async <filename> Creates a job to detect speech in a local audio file, and waits for the job to
complete.
recognize.js async-gcs <gcsUri> Creates a job to detect speech in an audio file located in a Google Cloud
Storage bucket, and waits for the job to complete.
recognize.js async-gcs-words <gcsUri> Creates a job to detect speech with word time offset in an audio file located
in a Google Cloud Storage bucket, and waits for the job to complete.
recognize.js stream <filename> Detects speech in a local audio file by streaming it to the Speech API.
recognize.js listen Detects speech in a microphone input stream. This command requires that you
have SoX installed and available in your $PATH. See
https://www.npmjs.com/package/node-record-lpcm16#dependencies

Options:
--version Show version number [boolean]
--encoding, -e [string] [default: "LINEAR16"]
--sampleRateHertz, -r [number] [default: 16000]
--languageCode, -l [string] [default: "en-US"]
--help Show help [boolean]

Examples:
node recognize.js sync ./resources/audio.raw -e LINEAR16 -r 16000
node recognize.js async-gcs gs://gcs-test-data/vr.flac -e FLAC -r 16000
node recognize.js stream ./resources/audio.raw -e LINEAR16 -r 16000
node recognize.js listen

For more information, see https://cloud.google.com/speech/docs
```

[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=speech.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
[recognize_0_docs]: https://cloud.google.com/speech/docs
[recognize_0_code]: recognize.js

### Installing the client library
### Speech Recognition v1p1beta1

npm install --save @google-cloud/speech
View the [source code][recognize.v1p1beta1_1_code].

### Using the client library
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.v1p1beta1.js,samples/README.md)

```javascript
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
const fs = require('fs');
__Usage:__ `node recognize.v1p1beta1.js --help`

// Creates a client
const client = new speech.SpeechClient();
```
recognize.v1p1beta1.js <command>

// The name of the audio file to transcribe
const fileName = './resources/audio.raw';
Commands:
recognize.v1p1beta1.js sync-model <filename> <model> Detects speech in a local audio file using provided model.
recognize.v1p1beta1.js sync-model-gcs <gcsUri> <model> Detects speech in an audio file located in a Google Cloud
Storage bucket using provided model.

// Reads a local audio file and converts it to base64
const file = fs.readFileSync(fileName);
const audioBytes = file.toString('base64');
Options:
--version Show version number [boolean]

This comment was marked as spam.

--encoding, -e [string] [default: "LINEAR16"]
--sampleRateHertz, -r [number] [default: 16000]
--languageCode, -l [string] [default: "en-US"]
--help Show help [boolean]

// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
};
const config = {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: 'en-US',
};
const request = {
audio: audio,
config: config,
};
Examples:
node recognize.v1p1beta1.js sync-model ./resources/Google_Gnome.wav video -e LINEAR16 -r 16000
node recognize.v1p1beta1.js sync-model-gcs gs://gcs-test-data/Google_Gnome.wav phone_call -e FLAC -r 16000

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


// Detects speech in the audio file
client
.recognize(request)
.then(data => {
const response = data[0];
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
console.log(`Transcription: ${transcription}`);
})
.catch(err => {
console.error('ERROR:', err);
});
For more information, see https://cloud.google.com/speech/docs
```

## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-speech/tree/master/samples) directory. The samples' `README.md`
has instructions for running the samples.
[recognize.v1p1beta1_1_docs]: https://cloud.google.com/speech/docs
[recognize.v1p1beta1_1_code]: recognize.v1p1beta1.js

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Speech Recognition | [source code](https://github.com/googleapis/nodejs-speech/blob/master/samples/recognize.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.js,samples/README.md) |
| Speech Recognition v1p1beta1 | [source code](https://github.com/googleapis/nodejs-speech/blob/master/samples/recognize.v1p1beta1.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.v1p1beta1.js,samples/README.md) |

The [Speech API Node.js Client API Reference][client-docs] documentation
also contains samples.
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/README.md

## Versioning
### betaFeatures v1p1beta1

This library follows [Semantic Versioning](http://semver.org/).
View the [source code][betaFeatures_code].

This library is considered to be **General Availability (GA)**. This means it
is stable; the code surface will not change in backwards-incompatible ways
unless absolutely necessary (e.g. because of critical security issues) or with
an extensive deprecation period. Issues and requests against **GA** libraries
are addressed with the highest priority.
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/betaFeatures.js,samples/README.md)

More Information: [Google Cloud Platform Launch Stages][launch_stages]
__Usage:__ `node betaFeatures.js --help`

[launch_stages]: https://cloud.google.com/terms/launch-stages
```
betaFeatures.js <command>

## Contributing
Commands:
betaFeatures.js sync-model <filename> <model> Detects speech in a local audio file using provided model.
betaFeatures.js sync-model-gcs <gcsUri> <model> Detects speech in an audio file located in a Google Cloud
Storage bucket using provided model.

Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-speech/blob/master/.github/CONTRIBUTING.md).
Options:
--version Show version number [boolean]
--encoding, -e [string] [default: "LINEAR16"]
--sampleRateHertz, -r [number] [default: 16000]
--languageCode, -l [string] [default: "en-US"]
--help Show help [boolean]

## License
Examples:
node betaFeatures.js sync-model ./resources/Google_Gnome.wav video -e LINEAR16 -r 16000
node betaFeatures.js sync-model-gcs gs://gcs-test-data/Google_Gnome.wav phone_call -e FLAC -r 16000

Apache Version 2.0
For more information, see https://cloud.google.com/speech/docs
```

See [LICENSE](https://github.com/googleapis/nodejs-speech/blob/master/LICENSE)
[betaFeatures_docs]: https://cloud.google.com/speech/docs
[betaFeatures_code]: betaFeatures.js

[client-docs]: https://cloud.google.com/nodejs/docs/reference/speech/latest/
[product-docs]: https://cloud.google.com/speech/docs
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/README.md
Loading