Skip to content
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: initial support #1407

Merged
merged 19 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This client supports the following Google Cloud Platform services:
* [Google Translate API](#google-translate-api)
* [Google Cloud Natural Language](#google-cloud-natural-language-beta) (Beta)
* [Google Cloud Resource Manager](#google-cloud-resource-manager-beta) (Beta)
* [Google Cloud Speech](#google-cloud-speech-beta) (Beta)
* [Google Cloud Vision](#google-cloud-vision-beta) (Beta)
* [Stackdriver Logging](#stackdriver-logging-beta) (Beta)

Expand Down Expand Up @@ -91,6 +92,7 @@ If you are not running this client on Google Compute Engine, you need a Google D
* Google Cloud Natural Language API
* Google Cloud Pub/Sub API
* Google Cloud Resource Manager API
* Google Cloud Speech API
* Google Cloud Storage
* Google Cloud Storage JSON API
* Google Cloud Vision API
Expand Down Expand Up @@ -848,6 +850,91 @@ project.getMetadata(function(err, metadata) {
```


## Google Cloud Speech (Beta)

> **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.

- [API Documentation][gcloud-speech-docs]
- [Official Documentation][cloud-speech-docs]

#### Using the all-in-one module

```
$ npm install --save google-cloud
```

```js
var gcloud = require('google-cloud');
var speech = gcloud.speech;
```

#### Using the Cloud Speech API module

```
$ npm install --save @google-cloud/speech
```

```js
var speech = require('@google-cloud/speech');
```

#### Preview

```js
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authentication section above).

var speechClient = gcloud.speech({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});

// Detect the speech in an audio file.
speechClient.recognize('./audio.raw', {
encoding: 'LINEAR16',

This comment was marked as spam.

This comment was marked as spam.

sampleRate: 16000

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}, 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',
sampleRate: 16000
},
singleUtterance: false,
interimResults: false
}))
.on('error', console.error)
.on('data', function(data) {
// The first "data" event emitted might look like:
// data = {
// endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
// results: "",
// ...
// }
//
// A later "data" event emitted might look like:
// data = {
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
// results: "",
// ...
// }
//
// A final "data" event emitted might look like:
// data = {
// endpointerType:
// Speech.endpointerTypes.ENDPOINTER_EVENT_UNSPECIFIED,
// results: "how old is the Brooklyn Bridge",
// ...
// }
});
```


## Google Cloud Vision (Beta)

> **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.
Expand Down Expand Up @@ -1073,6 +1160,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
[gcloud-prediction-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/prediction
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/pubsub
[gcloud-resource-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/resource
[gcloud-speech-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/speech
[gcloud-storage-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage
[gcloud-translate-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/translate
[gcloud-vision-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/vision
Expand Down Expand Up @@ -1119,4 +1207,6 @@ Apache 2.0 - See [COPYING](COPYING) for more information.

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

[cloud-speech-docs]: https://cloud.google.com/speech/docs

[cloud-vision-docs]: https://cloud.google.com/vision/docs
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@
"master"
]
},
{
"id": "speech",
"name": "@google-cloud/speech",
"defaultService": "speech",
"versions": [
"master"
]
},
{
"id": "storage",
"name": "@google-cloud/storage",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"semver": "^5.3.0",
"shelljs": "^0.7.3",
"string-format-obj": "^1.0.0",
"through2": "^2.0.0"
"through2": "^2.0.0",
"tmp": "0.0.28"
},
"scripts": {
"postinstall": "node ./scripts/install.js",
Expand Down
15 changes: 15 additions & 0 deletions packages/google-cloud/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var FakeLogging = createFakeApi();
var FakePrediction = createFakeApi();
var FakePubSub = createFakeApi();
var FakeResource = createFakeApi();
var FakeSpeech = createFakeApi();
var FakeStorage = createFakeApi();
var FakeTranslate = createFakeApi();
var FakeVision = createFakeApi();
Expand All @@ -61,6 +62,7 @@ describe('gcloud', function() {
'@google-cloud/prediction': FakePrediction,
'@google-cloud/pubsub': FakePubSub,
'@google-cloud/resource': FakeResource,
'@google-cloud/speech': FakeSpeech,
'@google-cloud/storage': FakeStorage,
'@google-cloud/translate': FakeTranslate,
'@google-cloud/vision': FakeVision
Expand Down Expand Up @@ -111,6 +113,10 @@ describe('gcloud', function() {
assert.strictEqual(gcloud.resource, FakeResource);
});

it('should export static speech', function() {
assert.strictEqual(gcloud.speech, FakeSpeech);
});

it('should export static storage', function() {
assert.strictEqual(gcloud.storage, FakeStorage);
});
Expand Down Expand Up @@ -244,6 +250,15 @@ describe('gcloud', function() {
});
});

describe('speech', function() {
it('should create a new Speech', function() {
var speech = localGcloud.speech(options);

assert(speech instanceof FakeSpeech);
assert.strictEqual(speech.calledWith_[0], options);
});
});

describe('storage', function() {
it('should create a new Storage', function() {
var storage = localGcloud.storage(options);
Expand Down
116 changes: 116 additions & 0 deletions packages/speech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# @google-cloud/speech
> Google Cloud Speech Client Library for Node.js

> **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.

*Looking for more Google APIs than just Speech? You might want to check out [`google-cloud`][google-cloud].*

- [API Documentation][gcloud-speech-docs]
- [Official Documentation][cloud-speech-docs]


```sh
$ npm install --save @google-cloud/speech
```
```js
var speech = require('@google-cloud/speech')({
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

// Detect the speech in an audio file.
speechClient.recognize('./audio.raw', {
encoding: 'LINEAR16',
sampleRate: 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',
sampleRate: 16000
},
singleUtterance: false,
interimResults: false
}))
.on('error', console.error)
.on('data', function(data) {
// The first "data" event emitted might look like:
// data = {
// endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
// ...
// }
//
// A later "data" event emitted might look like:
// data = {
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
// ...
// }
//
// A final "data" event emitted might look like:
// data = {
// endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
// results: "how old is the Brooklyn Bridge",
// ...
// }
});
```


## 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 Google Cloud services.

### On Google Compute Engine

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.

``` js
// Authenticating on a global basis.
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'

var speech = require('@google-cloud/speech')({
projectId: projectId
});

// ...you're good to go!
```

### Elsewhere

If you are not running this client on Google Compute Engine, 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, 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.
* 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.

``` 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!
```


[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
89 changes: 89 additions & 0 deletions packages/speech/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "@google-cloud/speech",
"version": "0.1.0",
"author": "Google Inc.",
"description": "Google Cloud Speech Client Library for Node.js",
"contributors": [
{
"name": "Burcu Dogan",
"email": "[email protected]"
},
{
"name": "Jason Dobry",
"email": "[email protected]"
},
{
"name": "Johan Euphrosine",
"email": "[email protected]"
},
{
"name": "Patrick Costello",
"email": "[email protected]"
},
{
"name": "Ryan Seys",
"email": "[email protected]"
},
{
"name": "Silvano Luciani",
"email": "[email protected]"
},
{
"name": "Stephen Sawchuk",
"email": "[email protected]"
}
],
"main": "./src/index.js",
"files": [
"./src/*",
"AUTHORS",
"CONTRIBUTORS",
"COPYING"
],
"repository": "googlecloudplatform/google-cloud-node",
"keywords": [
"google apis client",
"google api client",
"google apis",
"google api",
"google",
"google cloud platform",
"google cloud",
"cloud",
"google speech",
"speech"
],
"dependencies": {
"@google-cloud/common": "^0.5.0",
"events-intercept": "^2.0.0",
"extend": "^3.0.0",
"google-proto-files": "^0.7.0",
"is": "^3.1.0",
"modelo": "^4.2.0",
"propprop": "^0.3.1",
"pumpify": "^1.3.5",
"request": "^2.74.0",
"stream-events": "^1.0.1",
"string-format-obj": "^1.1.0",
"through2": "^2.0.1"
},
"devDependencies": {
"@google-cloud/storage": "*",
"async": "^2.0.1",
"methmeth": "^1.1.0",
"mocha": "^3.0.2",
"node-uuid": "^1.4.7",
"proxyquire": "^1.7.10",
"sinon": "^1.17.5",
"tmp": "0.0.28"
},
"scripts": {
"publish-module": "node ../../scripts/publish.js speech",
"test": "mocha test/*.js",
"system-test": "mocha system-test/*.js --no-timeouts --bail"
},
"license": "Apache-2.0",
"engines": {
"node": ">=0.12.0"
}
}
Loading