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

Add Speech API streaming sample. #144

Merged
merged 5 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test.
  • Loading branch information
jmdobry committed Jun 30, 2016
commit 750a6c1c41e04295da82780a9591be1a065c428d
15 changes: 15 additions & 0 deletions speech/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ Example:

[recognition_docs]: https://cloud.google.com/speech/
[recognition_code]: recognize.js

### Recognition (Streaming)

View the [documentation][recognition_streaming_docs] or the [source code][recognition_streaming_code].

__Run the sample:__

Usage: `node recognize_streaming <path-to-audio-file>`

Example:

node recognize_streaming "/path/to/audio.file"

[recognition_streaming_docs]: https://cloud.google.com/speech/
[recognition_streaming_code]: recognize_streaming.js
3 changes: 3 additions & 0 deletions speech/recognize_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function getSpeechService (callback) {
grpc.credentials.createFromGoogleCredential(authClient)
);

console.log('Loading speech service...');
var stub = new speechProto.Speech('speech.googleapis.com', credentials);
return callback(null, stub);
});
Expand Down Expand Up @@ -133,3 +134,5 @@ if (module === require.main) {
main(inputFile, console.log);
}
// [END run_application]

exports.main = main;
35 changes: 35 additions & 0 deletions test/speech/recognize_streaming.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016, Google, Inc.
// 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';

var path = require('path');
var recognizeExample = require('../../speech/recognize_streaming');

describe('speech:recognize_streaming', function () {
it('should list entries', function (done) {
recognizeExample.main(
path.join(__dirname, '../../speech/resources/audio.raw'),
function (err, results) {
assert(!err);
assert(results);
assert(results.length === 1);
assert(results[0].results);
assert(console.log.calledWith('Got audio file!'));
assert(console.log.calledWith('Loading speech service...'));
assert(console.log.calledWith('Analyzing speech...'));
done();
}
);
});
});