-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speech Partial Veneer #2421
Speech Partial Veneer #2421
Changes from 28 commits
ab565ea
070807e
553bcd1
83611e1
2c00c70
6d5684e
41ed049
e5ffcf3
981e861
53e087a
bbaf415
04aca35
7207adf
c699d90
2459348
667f6a4
6f3caf6
da27074
5dfd111
cb1f005
3e79c34
48e47e2
3da9fd6
231614c
608c06d
33c30aa
ff0c6ec
d853a8d
7adecc2
b95453c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
**/*.log | ||
**/node_modules | ||
coverage | ||
.coverage | ||
.nyc_output | ||
docs/json | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
**/system-test/*/**/* | ||
**/test/*/**/* | ||
**/node_modules/ | ||
**/coverage | ||
**/coverage/ | ||
**/gapic*.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"report-dir": "./.coverage", | ||
"exclude": [ | ||
"src/*{/*,/**/*}.js", | ||
"src/v*/*.js", | ||
"test/**/*.js" | ||
], | ||
"watermarks": { | ||
"branches": [ | ||
95, | ||
100 | ||
], | ||
"functions": [ | ||
95, | ||
100 | ||
], | ||
"lines": [ | ||
95, | ||
100 | ||
], | ||
"statements": [ | ||
95, | ||
100 | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,59 @@ | ||
# @google-cloud/speech ([Alpha][versioning]) | ||
> Cloud Speech Client Library for Node.js | ||
# Node.js Client for Google Cloud Speech API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning)) | ||
|
||
*Looking for more Google APIs than just Speech? You might want to check out [`google-cloud`][google-cloud].* | ||
[Google Cloud Speech API][Product Documentation]: Google Cloud Speech API. | ||
- [Client Library Documentation][] | ||
- [Product Documentation][] | ||
|
||
- [API Documentation][gcloud-speech-docs] | ||
- [Official Documentation][cloud-speech-docs] | ||
## Quick Start | ||
In order to use this library, you first need to go through the following steps: | ||
|
||
1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) | ||
2. [Enable the Google Cloud Speech API.](https://console.cloud.google.com/apis/api/speech) | ||
3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication) | ||
|
||
```sh | ||
$ npm install --save @google-cloud/speech | ||
### Installation | ||
``` | ||
```js | ||
var speech = require('@google-cloud/speech')({ | ||
projectId: 'grape-spaceship-123', | ||
keyFilename: '/path/to/keyfile.json' | ||
}); | ||
|
||
// Detect the speech in an audio file. | ||
speech.recognize('./audio.raw', { | ||
encoding: 'LINEAR16', | ||
sampleRateHertz: 16000 | ||
}, function(err, transcript) { | ||
// transcript = 'how old is the Brooklyn Bridge' | ||
}); | ||
|
||
// Detect the speech in an audio file stream. | ||
fs.createReadStream('./audio.raw') | ||
.on('error', console.error) | ||
.pipe(speech.createRecognizeStream({ | ||
config: { | ||
encoding: 'LINEAR16', | ||
sampleRateHertz: 16000 | ||
}, | ||
singleUtterance: false, | ||
interimResults: false | ||
})) | ||
.on('error', console.error) | ||
.on('data', function(data) { | ||
// data.results = "how old is the Brooklyn Bridge" | ||
}); | ||
|
||
// Promises are also supported by omitting callbacks. | ||
speech.recognize('./audio.raw', { | ||
encoding: 'LINEAR16', | ||
sampleRateHertz: 16000 | ||
}).then(function(data) { | ||
var transcript = data[0]; | ||
}); | ||
|
||
// It's also possible to integrate with third-party Promise libraries. | ||
var speech = require('@google-cloud/speech')({ | ||
promise: require('bluebird') | ||
}); | ||
``` | ||
|
||
|
||
## Authentication | ||
|
||
It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services. | ||
|
||
### On Google Cloud Platform | ||
|
||
If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access. | ||
|
||
``` js | ||
var speech = require('@google-cloud/speech')(); | ||
// ...you're good to go! | ||
$ npm install --save @google-cloud/speech | ||
``` | ||
|
||
### Elsewhere | ||
|
||
If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account: | ||
|
||
1. Visit the [Google Developers Console][dev-console]. | ||
2. Create a new project or click on an existing project. | ||
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services): | ||
* Google Cloud Speech API | ||
4. Navigate to **APIs & auth** > **Credentials** and then: | ||
* If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests. | ||
* If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file. | ||
|
||
``` js | ||
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123' | ||
|
||
var speech = require('@google-cloud/speech')({ | ||
projectId: projectId, | ||
|
||
// The path to your key file: | ||
keyFilename: '/path/to/keyfile.json' | ||
|
||
// Or the contents of the key file: | ||
credentials: require('./path/to/keyfile.json') | ||
}); | ||
|
||
// ...you're good to go! | ||
### Preview | ||
#### SpeechClient | ||
```js | ||
var speech = require('@google-cloud/speech'); | ||
|
||
var client = speech({ | ||
// optional auth parameters. | ||
}); | ||
|
||
var languageCode = 'en-US'; | ||
var sampleRateHertz = 44100; | ||
var encoding = speech.v1.types.RecognitionConfig.AudioEncoding.FLAC; | ||
var config = { | ||
languageCode : languageCode, | ||
sampleRateHertz : sampleRateHertz, | ||
encoding : encoding | ||
}; | ||
var uri = 'gs://gapic-toolkit/hello.flac'; | ||
var audio = { | ||
uri : uri | ||
}; | ||
var request = { | ||
config: config, | ||
audio: audio | ||
}; | ||
client.recognize(request).then(function(responses) { | ||
var response = responses[0]; | ||
// doThingsWith(response) | ||
}) | ||
.catch(function(err) { | ||
console.error(err); | ||
}); | ||
``` | ||
|
||
### Next Steps | ||
- Read the [Client Library Documentation][] for Google Cloud Speech API to see other available methods on the client. | ||
- Read the [Google Cloud Speech API Product documentation][Product Documentation] to learn more about the product and see How-to Guides. | ||
- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover. | ||
|
||
[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning | ||
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/ | ||
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using | ||
[dev-console]: https://console.developers.google.com/project | ||
[gcloud-speech-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/speech | ||
[cloud-speech-docs]: https://cloud.google.com/speech | ||
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/speech | ||
[Product Documentation]: https://cloud.google.com/speech |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2017, Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
describe('SpeechSmokeTest', function() { | ||
|
||
it('successfully makes a call to the service', function(done) { | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
var speech = require('../src'); | ||
|
||
var client = speech.v1({ | ||
// optional auth parameters. | ||
}); | ||
|
||
var languageCode = 'en-US'; | ||
var sampleRateHertz = 44100; | ||
var encoding = speech.v1.types.RecognitionConfig.AudioEncoding.FLAC; | ||
var config = { | ||
languageCode : languageCode, | ||
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. |
||
sampleRateHertz : sampleRateHertz, | ||
encoding : encoding | ||
}; | ||
var uri = 'gs://gapic-toolkit/hello.flac'; | ||
var audio = { | ||
uri : uri | ||
}; | ||
var request = { | ||
config: config, | ||
audio: audio | ||
}; | ||
client.recognize(request).then(function(responses) { | ||
var response = responses[0]; | ||
console.log(response); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
}) | ||
.then(done) | ||
.catch(done); | ||
}); | ||
}); |
This comment was marked as spam.
Sorry, something went wrong.