Skip to content

Commit d24209a

Browse files
jmdobrycallmehiphop
authored andcommitted
speech: initial support (#1407)
1 parent af8ca8d commit d24209a

File tree

17 files changed

+2508
-3
lines changed

17 files changed

+2508
-3
lines changed

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This client supports the following Google Cloud Platform services:
2323
* [Google Translate API](#google-translate-api)
2424
* [Google Cloud Natural Language](#google-cloud-natural-language-beta) (Beta)
2525
* [Google Cloud Resource Manager](#google-cloud-resource-manager-beta) (Beta)
26+
* [Google Cloud Speech](#google-cloud-speech-beta) (Beta)
2627
* [Google Cloud Vision](#google-cloud-vision-beta) (Beta)
2728
* [Stackdriver Logging](#stackdriver-logging-beta) (Beta)
2829

@@ -92,6 +93,7 @@ If you are not running this client on Google Compute Engine, you need a Google D
9293
* Google Cloud Natural Language API
9394
* Google Cloud Pub/Sub API
9495
* Google Cloud Resource Manager API
96+
* Google Cloud Speech API
9597
* Google Cloud Storage
9698
* Google Cloud Storage JSON API
9799
* Google Cloud Vision API
@@ -849,6 +851,91 @@ project.getMetadata(function(err, metadata) {
849851
```
850852

851853

854+
## Google Cloud Speech (Beta)
855+
856+
> **This is a Beta release of Google Cloud Speech.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
857+
858+
- [API Documentation][gcloud-speech-docs]
859+
- [Official Documentation][cloud-speech-docs]
860+
861+
#### Using the all-in-one module
862+
863+
```
864+
$ npm install --save google-cloud
865+
```
866+
867+
```js
868+
var gcloud = require('google-cloud');
869+
var speech = gcloud.speech;
870+
```
871+
872+
#### Using the Cloud Speech API module
873+
874+
```
875+
$ npm install --save @google-cloud/speech
876+
```
877+
878+
```js
879+
var speech = require('@google-cloud/speech');
880+
```
881+
882+
#### Preview
883+
884+
```js
885+
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
886+
// global basis (see Authentication section above).
887+
888+
var speechClient = gcloud.speech({
889+
projectId: 'my-project',
890+
keyFilename: '/path/to/keyfile.json'
891+
});
892+
893+
// Detect the speech in an audio file.
894+
speechClient.recognize('./audio.raw', {
895+
encoding: 'LINEAR16',
896+
sampleRate: 16000
897+
}, function(err, transcript) {
898+
// transcript = 'how old is the Brooklyn Bridge'
899+
});
900+
901+
// Detect the speech in an audio file stream.
902+
fs.createReadStream('./audio.raw')
903+
.on('error', console.error)
904+
.pipe(speech.createRecognizeStream({
905+
config: {
906+
encoding: 'LINEAR16',
907+
sampleRate: 16000
908+
},
909+
singleUtterance: false,
910+
interimResults: false
911+
}))
912+
.on('error', console.error)
913+
.on('data', function(data) {
914+
// The first "data" event emitted might look like:
915+
// data = {
916+
// endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
917+
// results: "",
918+
// ...
919+
// }
920+
//
921+
// A later "data" event emitted might look like:
922+
// data = {
923+
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
924+
// results: "",
925+
// ...
926+
// }
927+
//
928+
// A final "data" event emitted might look like:
929+
// data = {
930+
// endpointerType:
931+
// Speech.endpointerTypes.ENDPOINTER_EVENT_UNSPECIFIED,
932+
// results: "how old is the Brooklyn Bridge",
933+
// ...
934+
// }
935+
});
936+
```
937+
938+
852939
## Google Cloud Vision (Beta)
853940

854941
> **This is a Beta release of Google Cloud Vision.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
@@ -1074,6 +1161,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
10741161
[gcloud-prediction-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/prediction
10751162
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/pubsub
10761163
[gcloud-resource-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/resource
1164+
[gcloud-speech-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/speech
10771165
[gcloud-storage-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage
10781166
[gcloud-translate-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/translate
10791167
[gcloud-vision-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/vision
@@ -1120,4 +1208,6 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
11201208

11211209
[cloud-translate-docs]: https://cloud.google.com/translate/docs
11221210

1211+
[cloud-speech-docs]: https://cloud.google.com/speech/docs
1212+
11231213
[cloud-vision-docs]: https://cloud.google.com/vision/docs

docs/json/master/speech/.gitkeep

Whitespace-only changes.

docs/json/speech/master/.gitkeep

Whitespace-only changes.

docs/manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@
164164
"master"
165165
]
166166
},
167+
{
168+
"id": "speech",
169+
"name": "@google-cloud/speech",
170+
"defaultService": "speech",
171+
"versions": [
172+
"master"
173+
]
174+
},
167175
{
168176
"id": "storage",
169177
"name": "@google-cloud/storage",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"semver": "^5.3.0",
2323
"shelljs": "^0.7.3",
2424
"string-format-obj": "^1.0.0",
25-
"through2": "^2.0.0"
25+
"through2": "^2.0.0",
26+
"tmp": "0.0.28"
2627
},
2728
"scripts": {
2829
"postinstall": "node ./scripts/install.js",

packages/google-cloud/test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var FakeLogging = createFakeApi();
4242
var FakePrediction = createFakeApi();
4343
var FakePubSub = createFakeApi();
4444
var FakeResource = createFakeApi();
45+
var FakeSpeech = createFakeApi();
4546
var FakeStorage = createFakeApi();
4647
var FakeTranslate = createFakeApi();
4748
var FakeVision = createFakeApi();
@@ -61,6 +62,7 @@ describe('gcloud', function() {
6162
'@google-cloud/prediction': FakePrediction,
6263
'@google-cloud/pubsub': FakePubSub,
6364
'@google-cloud/resource': FakeResource,
65+
'@google-cloud/speech': FakeSpeech,
6466
'@google-cloud/storage': FakeStorage,
6567
'@google-cloud/translate': FakeTranslate,
6668
'@google-cloud/vision': FakeVision
@@ -111,6 +113,10 @@ describe('gcloud', function() {
111113
assert.strictEqual(gcloud.resource, FakeResource);
112114
});
113115

116+
it('should export static speech', function() {
117+
assert.strictEqual(gcloud.speech, FakeSpeech);
118+
});
119+
114120
it('should export static storage', function() {
115121
assert.strictEqual(gcloud.storage, FakeStorage);
116122
});
@@ -244,6 +250,15 @@ describe('gcloud', function() {
244250
});
245251
});
246252

253+
describe('speech', function() {
254+
it('should create a new Speech', function() {
255+
var speech = localGcloud.speech(options);
256+
257+
assert(speech instanceof FakeSpeech);
258+
assert.strictEqual(speech.calledWith_[0], options);
259+
});
260+
});
261+
247262
describe('storage', function() {
248263
it('should create a new Storage', function() {
249264
var storage = localGcloud.storage(options);

packages/speech/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# @google-cloud/speech
2+
> Google Cloud Speech Client Library for Node.js
3+
4+
> **This is a Beta release of Google Cloud Speech.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
5+
6+
*Looking for more Google APIs than just Speech? You might want to check out [`google-cloud`][google-cloud].*
7+
8+
- [API Documentation][gcloud-speech-docs]
9+
- [Official Documentation][cloud-speech-docs]
10+
11+
12+
```sh
13+
$ npm install --save @google-cloud/speech
14+
```
15+
```js
16+
var speech = require('@google-cloud/speech')({
17+
projectId: 'grape-spaceship-123',
18+
keyFilename: '/path/to/keyfile.json'
19+
});
20+
21+
// Detect the speech in an audio file.
22+
speechClient.recognize('./audio.raw', {
23+
encoding: 'LINEAR16',
24+
sampleRate: 16000
25+
}, function(err, transcript) {
26+
// transcript = 'how old is the Brooklyn Bridge'
27+
});
28+
29+
// Detect the speech in an audio file stream.
30+
fs.createReadStream('./audio.raw')
31+
.on('error', console.error)
32+
.pipe(speech.createRecognizeStream({
33+
config: {
34+
encoding: 'LINEAR16',
35+
sampleRate: 16000
36+
},
37+
singleUtterance: false,
38+
interimResults: false
39+
}))
40+
.on('error', console.error)
41+
.on('data', function(data) {
42+
// The first "data" event emitted might look like:
43+
// data = {
44+
// endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
45+
// ...
46+
// }
47+
//
48+
// A later "data" event emitted might look like:
49+
// data = {
50+
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
51+
// ...
52+
// }
53+
//
54+
// A final "data" event emitted might look like:
55+
// data = {
56+
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
57+
// results: "how old is the Brooklyn Bridge",
58+
// ...
59+
// }
60+
});
61+
```
62+
63+
64+
## Authentication
65+
66+
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 Google Cloud services.
67+
68+
### On Google Compute Engine
69+
70+
If you are running this client on Google Compute Engine, 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.
71+
72+
``` js
73+
// Authenticating on a global basis.
74+
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
75+
76+
var speech = require('@google-cloud/speech')({
77+
projectId: projectId
78+
});
79+
80+
// ...you're good to go!
81+
```
82+
83+
### Elsewhere
84+
85+
If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:
86+
87+
1. Visit the [Google Developers Console][dev-console].
88+
2. Create a new project or click on an existing project.
89+
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):
90+
* Google Cloud Speech API
91+
4. Navigate to **APIs & auth** > **Credentials** and then:
92+
* If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
93+
* If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
94+
95+
``` js
96+
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
97+
98+
var speech = require('@google-cloud/speech')({
99+
projectId: projectId,
100+
101+
// The path to your key file:
102+
keyFilename: '/path/to/keyfile.json'
103+
104+
// Or the contents of the key file:
105+
credentials: require('./path/to/keyfile.json')
106+
});
107+
108+
// ...you're good to go!
109+
```
110+
111+
112+
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/
113+
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
114+
[dev-console]: https://console.developers.google.com/project
115+
[gcloud-speech-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/speech
116+
[cloud-speech-docs]: https://cloud.google.com/speech

packages/speech/package.json

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"name": "@google-cloud/speech",
3+
"version": "0.1.0",
4+
"author": "Google Inc.",
5+
"description": "Google Cloud Speech Client Library for Node.js",
6+
"contributors": [
7+
{
8+
"name": "Burcu Dogan",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Jason Dobry",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Johan Euphrosine",
17+
"email": "[email protected]"
18+
},
19+
{
20+
"name": "Patrick Costello",
21+
"email": "[email protected]"
22+
},
23+
{
24+
"name": "Ryan Seys",
25+
"email": "[email protected]"
26+
},
27+
{
28+
"name": "Silvano Luciani",
29+
"email": "[email protected]"
30+
},
31+
{
32+
"name": "Stephen Sawchuk",
33+
"email": "[email protected]"
34+
}
35+
],
36+
"main": "./src/index.js",
37+
"files": [
38+
"./src/*",
39+
"AUTHORS",
40+
"CONTRIBUTORS",
41+
"COPYING"
42+
],
43+
"repository": "googlecloudplatform/google-cloud-node",
44+
"keywords": [
45+
"google apis client",
46+
"google api client",
47+
"google apis",
48+
"google api",
49+
"google",
50+
"google cloud platform",
51+
"google cloud",
52+
"cloud",
53+
"google speech",
54+
"speech"
55+
],
56+
"dependencies": {
57+
"@google-cloud/common": "^0.5.0",
58+
"events-intercept": "^2.0.0",
59+
"extend": "^3.0.0",
60+
"google-proto-files": "^0.7.0",
61+
"is": "^3.1.0",
62+
"modelo": "^4.2.0",
63+
"propprop": "^0.3.1",
64+
"pumpify": "^1.3.5",
65+
"request": "^2.74.0",
66+
"stream-events": "^1.0.1",
67+
"string-format-obj": "^1.1.0",
68+
"through2": "^2.0.1"
69+
},
70+
"devDependencies": {
71+
"@google-cloud/storage": "*",
72+
"async": "^2.0.1",
73+
"methmeth": "^1.1.0",
74+
"mocha": "^3.0.2",
75+
"node-uuid": "^1.4.7",
76+
"proxyquire": "^1.7.10",
77+
"sinon": "^1.17.5",
78+
"tmp": "0.0.28"
79+
},
80+
"scripts": {
81+
"publish-module": "node ../../scripts/publish.js speech",
82+
"test": "mocha test/*.js",
83+
"system-test": "mocha system-test/*.js --no-timeouts --bail"
84+
},
85+
"license": "Apache-2.0",
86+
"engines": {
87+
"node": ">=0.12.0"
88+
}
89+
}

0 commit comments

Comments
 (0)