This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
Code Samples for new v1p1beta1 features #118
Merged
Merged
Changes from 40 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
b823117
MicrophoneStreamTest, and basic .ava tests-
53cd4f0
Just cosmetic, removed some notes, added note about Event style for t…
d13734f
removed .test, cleaned up yaaarghs
709638b
Cleaned up test within MicStream.js, .ava tests forthcoming
a27324c
Merge branch 'master' into master
JustinBeckwith 6c452f7
Pruned down to core streaming function, yaargs rebuilt, .ava upcoming
b6add2d
Merge branch 'master' of https://github.com/CallistoCF/nodejs-speech
6f44c0c
newest .ava test, just makes sure yaargs loads, comments addressed
9e0bf4c
Added Readme
CallistoCF ad8007c
BetaFeatures for Test, fixed from yesterday
3e77731
Updated Readme
CallistoCF 3504280
Updated Readme, fixed old paths used in testing
CallistoCF 2974091
Updated Readme again
CallistoCF be3869f
Updated Yaargs Examples to fit readme
CallistoCF 0fbba57
Fixed Diarization bug
554af87
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
0cad177
Merge branch 'master' into BetaFeatures
CallistoCF e0caf82
Merge branch 'master' of https://github.com/CallistoCF/nodejs-speech …
950844e
Speech Fixes
c365046
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
27b42dc
fixing eslint settings to merge
e583e2e
eslint again
c3840eb
testing lint quick fix
054e7f8
more ESlint shennanigans
b3174dd
cleaned up region tags
37ae0a6
Removed audiochannelGCS
3c5ae14
Removed Comments, also multiChannel GCS
CallistoCF da0736f
Removed Comments, GCS MultiChannel
CallistoCF 44d6502
Removed multi Audio Channel
CallistoCF 45418b2
Added mono-channel multi Language file to sample
CallistoCF 6b793e0
removed old console.log
CallistoCF 24cdc11
fixed todos and filename -> fileName
CallistoCF 5487a88
removed docstrings
CallistoCF 7852924
removed enableWordTimeOffsets in WordLvlConfidence
CallistoCF 10bad72
rebuild
720f8fa
fixed space
3a18194
Merge branch 'master' into BetaFeatures
CallistoCF b6fee39
fixed package.lock for node8 circleCI
b0b0748
Attempted fix for circleCI node 8
701088b
attempted mime-types fix
0f4ea7a
possible mime/CLI fix
832b91d
Merged Latest package chore stuff, for circleCI
9e67988
Merge branch 'master' into BetaFeatures
JustinBeckwith e0f9d1d
all outstanding comments, except eslint issue
e95c8b3
Merge branch 'BetaFeatures' of https://github.com/CallistoCF/nodejs-s…
cde3b24
confidence test fix
0331ea0
fixed eslinting in betaFeatures.js
0340b1e
eslint again
b024d2e
Fixed MultiChannel transcribe
f2d15c7
multiChannelGCS test
1808096
Updated readme
ed26504
updated readme, scaffolding
7cf0fa3
readme again
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ rules: | |
block-scoped-var: error | ||
eqeqeq: error | ||
no-warning-comments: warn | ||
no-unsupported-features: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=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] | ||
--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.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
// 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.