Skip to content

Commit 5ad7894

Browse files
jmukstephenplusplus
authored andcommitted
Regenerate speech API. Now it contains streamingRecognize method. (#1775)
1 parent c60b607 commit 5ad7894

File tree

4 files changed

+76
-45
lines changed

4 files changed

+76
-45
lines changed

packages/google-cloud-speech/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@google-cloud/common": "^0.7.0",
5858
"events-intercept": "^2.0.0",
5959
"extend": "^3.0.0",
60-
"google-gax": "^0.8.1",
60+
"google-gax": "^0.9.1",
6161
"google-proto-files": "^0.8.0",
6262
"is": "^3.1.0",
6363
"modelo": "^4.2.0",

packages/google-cloud-speech/src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,18 +472,13 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
472472
Speech.prototype.createRecognizeStream = function(config) {
473473
var self = this;
474474

475-
var protoOpts = {
476-
service: 'Speech',
477-
method: 'streamingRecognize'
478-
};
479-
480475
var verboseMode = config.verbose === true;
481476
delete config.verbose;
482477

483478
var recognizeStream = streamEvents(pumpify.obj());
484479

485480
recognizeStream.once('writing', function() {
486-
var requestStream = self.requestWritableStream(protoOpts);
481+
var requestStream = self.api.Speech.streamingRecognize();
487482

488483
requestStream.on('response', function(response) {
489484
recognizeStream.emit('response', response);

packages/google-cloud-speech/src/v1beta1/speech_api.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ var DEFAULT_SERVICE_PORT = 443;
3737

3838
var CODE_GEN_NAME_VERSION = 'gapic/0.1.0';
3939

40+
var STREAM_DESCRIPTORS = {
41+
streamingRecognize: new gax.StreamDescriptor(gax.StreamType.BIDI_STREAMING)
42+
};
4043

4144
/**
4245
* The scopes needed to make gRPC calls to all of the methods defined in
@@ -80,8 +83,6 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
8083
'google.cloud.speech.v1beta1.Speech',
8184
configData,
8285
clientConfig,
83-
null,
84-
null,
8586
{'x-goog-api-client': googleApiClient});
8687

8788
var speechStub = gaxGrpc.createStub(
@@ -91,14 +92,16 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
9192
{sslCreds: sslCreds});
9293
var speechStubMethods = [
9394
'syncRecognize',
94-
'asyncRecognize'
95+
'asyncRecognize',
96+
'streamingRecognize'
9597
];
9698
speechStubMethods.forEach(function(methodName) {
9799
this['_' + methodName] = gax.createApiCall(
98100
speechStub.then(function(speechStub) {
99101
return speechStub[methodName].bind(speechStub);
100102
}),
101-
defaults[methodName]);
103+
defaults[methodName],
104+
STREAM_DESCRIPTORS[methodName]);
102105
}.bind(this));
103106
}
104107

@@ -208,6 +211,35 @@ SpeechApi.prototype.asyncRecognize = function(request, options, callback) {
208211
return this._asyncRecognize(request, options, callback);
209212
};
210213

214+
/**
215+
* Perform bidirectional streaming speech-recognition: receive results while
216+
* sending audio. This method is only available via the gRPC API (not REST).
217+
*
218+
* @param {Object=} options
219+
* Optional parameters. You can override the default settings for this call, e.g, timeout,
220+
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
221+
* @returns {Stream}
222+
* An object stream which is both readable and writable. It accepts objects
223+
* representing [StreamingRecognizeRequest]{@link StreamingRecognizeRequest} for write() method, and
224+
* will emit objects representing [StreamingRecognizeResponse]{@link StreamingRecognizeResponse} on 'data' event asynchronously.
225+
*
226+
* @example
227+
*
228+
* var api = speechV1beta1.speechApi();
229+
* var stream = api.streamingRecognize().on('data', function(response) {
230+
* // doThingsWith(response);
231+
* });
232+
* var request = {};
233+
* // Write request objects.
234+
* stream.write(request);
235+
*/
236+
SpeechApi.prototype.streamingRecognize = function(options) {
237+
if (options === undefined) {
238+
options = {};
239+
}
240+
return this._streamingRecognize(options);
241+
};
242+
211243
function SpeechApiBuilder(gaxGrpc) {
212244
if (!(this instanceof SpeechApiBuilder)) {
213245
return new SpeechApiBuilder(gaxGrpc);

packages/google-cloud-speech/test/index.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,20 @@ describe('Speech', function() {
448448

449449
stream.setPipeline = util.noop;
450450

451-
speech.requestWritableStream = function() {
452-
requestStream = through.obj();
453-
return requestStream;
451+
speech.api.Speech = {
452+
streamingRecognize: function() {
453+
requestStream = through.obj();
454+
return requestStream;
455+
}
454456
};
455457
});
456458

457459
it('should make the correct request once writing started', function(done) {
458-
speech.requestWritableStream = function(protoOpts) {
459-
assert.deepEqual(protoOpts, {
460-
service: 'Speech',
461-
method: 'streamingRecognize'
462-
});
463-
464-
setImmediate(done);
465-
466-
return through.obj();
460+
speech.api.Speech = {
461+
streamingRecognize: function() {
462+
setImmediate(done);
463+
return through.obj();
464+
}
467465
};
468466

469467
stream.emit('writing');
@@ -477,31 +475,35 @@ describe('Speech', function() {
477475
done();
478476
});
479477

480-
speech.requestWritableStream = function() {
481-
var requestStream = through.obj();
478+
speech.api.Speech = {
479+
streamingRecognize: function() {
480+
var requestStream = through.obj();
482481

483-
setImmediate(function() {
484-
requestStream.emit('response', response);
485-
});
482+
setImmediate(function() {
483+
requestStream.emit('response', response);
484+
});
486485

487-
return requestStream;
486+
return requestStream;
487+
}
488488
};
489489

490490
stream.emit('writing');
491491
});
492492

493493
it('should send the initial write to the request stream', function(done) {
494-
speech.requestWritableStream = function() {
495-
var requestStream = through.obj();
494+
speech.api.Speech = {
495+
streamingRecognize: function() {
496+
var requestStream = through.obj();
496497

497-
requestStream.once('data', function(data) {
498-
assert.deepEqual(data, {
499-
streamingConfig: CONFIG
498+
requestStream.once('data', function(data) {
499+
assert.deepEqual(data, {
500+
streamingConfig: CONFIG
501+
});
502+
done();
500503
});
501-
done();
502-
});
503504

504-
return requestStream;
505+
return requestStream;
506+
}
505507
};
506508

507509
stream.emit('writing');
@@ -582,17 +584,19 @@ describe('Speech', function() {
582584
verbose: true
583585
});
584586

585-
speech.requestWritableStream = function() {
586-
var stream = through.obj();
587+
speech.api.Speech = {
588+
streamingRecognize: function() {
589+
var stream = through.obj();
587590

588-
stream.on('data', function(data) {
589-
assert.deepEqual(data, {
590-
streamingConfig: {} // No `verbose` property.
591+
stream.on('data', function(data) {
592+
assert.deepEqual(data, {
593+
streamingConfig: {} // No `verbose` property.
594+
});
595+
done();
591596
});
592-
done();
593-
});
594597

595-
return stream;
598+
return stream;
599+
}
596600
};
597601

598602
stream.emit('writing');

0 commit comments

Comments
 (0)