Skip to content

Commit 8755b9c

Browse files
speech: update gapic layer (#1737)
1 parent 640b4e0 commit 8755b9c

File tree

4 files changed

+61
-63
lines changed

4 files changed

+61
-63
lines changed

packages/google-cloud-node/package.json

+1-1
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.7.0",
60+
"google-gax": "^0.8.1",
6161
"google-proto-files": "^0.8.0",
6262
"is": "^3.1.0",
6363
"modelo": "^4.2.0",

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,10 @@ Speech.prototype.recognize = function(file, config, callback) {
659659
return;
660660
}
661661

662-
self.api.Speech.syncRecognize(config, foundFile, function(err, resp) {
662+
self.api.Speech.syncRecognize({
663+
config: config,
664+
audio: foundFile
665+
}, function(err, resp) {
663666
if (err) {
664667
callback(err, null, resp);
665668
return;
@@ -799,7 +802,10 @@ Speech.prototype.startRecognition = function(file, config, callback) {
799802
return;
800803
}
801804

802-
self.api.Speech.asyncRecognize(config, foundFile, function(err, resp) {
805+
self.api.Speech.asyncRecognize({
806+
config: config,
807+
audio: foundFile
808+
}, function(err, resp) {
803809
if (err) {
804810
callback(err, null, resp);
805811
return;

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

+30-38
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
108108
* Perform synchronous speech-recognition: receive results after all audio
109109
* has been sent and processed.
110110
*
111-
* @param {Object} config
111+
* @param {Object} request
112+
* The request object that will be sent.
113+
* @param {Object} request.config
112114
* [Required] The `config` message provides information to the recognizer
113115
* that specifies how to process the request.
114116
*
115117
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
116-
* @param {Object} audio
118+
* @param {Object} request.audio
117119
* [Required] The audio data to be recognized.
118120
*
119121
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
@@ -124,39 +126,33 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
124126
* The function which will be called with the result of the API call.
125127
*
126128
* The second parameter to the callback is an object representing [SyncRecognizeResponse]{@link SyncRecognizeResponse}
127-
* @returns {gax.EventEmitter} - the event emitter to handle the call
128-
* status.
129+
* @returns {Promise} - The promise which resolves to the response object.
130+
* The promise has a method named "cancel" which cancels the ongoing API call.
129131
*
130132
* @example
131133
*
132134
* var api = speechV1beta1.speechApi();
133135
* var config = {};
134136
* var audio = {};
135-
* api.syncRecognize(config, audio, function(err, response) {
136-
* if (err) {
137-
* console.error(err);
138-
* return;
139-
* }
137+
* var request = {
138+
* config: config,
139+
* audio: audio
140+
* };
141+
* api.syncRecognize(request).then(function(response) {
140142
* // doThingsWith(response)
143+
* }).catch(function(err) {
144+
* console.error(err);
141145
* });
142146
*/
143-
SpeechApi.prototype.syncRecognize = function syncRecognize(
144-
config,
145-
audio,
146-
options,
147-
callback) {
147+
SpeechApi.prototype.syncRecognize = function(request, options, callback) {
148148
if (options instanceof Function && callback === undefined) {
149149
callback = options;
150150
options = {};
151151
}
152152
if (options === undefined) {
153153
options = {};
154154
}
155-
var req = {
156-
config: config,
157-
audio: audio
158-
};
159-
return this._syncRecognize(req, options, callback);
155+
return this._syncRecognize(request, options, callback);
160156
};
161157

162158
/**
@@ -165,12 +161,14 @@ SpeechApi.prototype.syncRecognize = function syncRecognize(
165161
* `Operation.error` or an `Operation.response` which contains
166162
* an `AsyncRecognizeResponse` message.
167163
*
168-
* @param {Object} config
164+
* @param {Object} request
165+
* The request object that will be sent.
166+
* @param {Object} request.config
169167
* [Required] The `config` message provides information to the recognizer
170168
* that specifies how to process the request.
171169
*
172170
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
173-
* @param {Object} audio
171+
* @param {Object} request.audio
174172
* [Required] The audio data to be recognized.
175173
*
176174
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
@@ -181,39 +179,33 @@ SpeechApi.prototype.syncRecognize = function syncRecognize(
181179
* The function which will be called with the result of the API call.
182180
*
183181
* The second parameter to the callback is an object representing [google.longrunning.Operation]{@link external:"google.longrunning.Operation"}
184-
* @returns {gax.EventEmitter} - the event emitter to handle the call
185-
* status.
182+
* @returns {Promise} - The promise which resolves to the response object.
183+
* The promise has a method named "cancel" which cancels the ongoing API call.
186184
*
187185
* @example
188186
*
189187
* var api = speechV1beta1.speechApi();
190188
* var config = {};
191189
* var audio = {};
192-
* api.asyncRecognize(config, audio, function(err, response) {
193-
* if (err) {
194-
* console.error(err);
195-
* return;
196-
* }
190+
* var request = {
191+
* config: config,
192+
* audio: audio
193+
* };
194+
* api.asyncRecognize(request).then(function(response) {
197195
* // doThingsWith(response)
196+
* }).catch(function(err) {
197+
* console.error(err);
198198
* });
199199
*/
200-
SpeechApi.prototype.asyncRecognize = function asyncRecognize(
201-
config,
202-
audio,
203-
options,
204-
callback) {
200+
SpeechApi.prototype.asyncRecognize = function(request, options, callback) {
205201
if (options instanceof Function && callback === undefined) {
206202
callback = options;
207203
options = {};
208204
}
209205
if (options === undefined) {
210206
options = {};
211207
}
212-
var req = {
213-
config: config,
214-
audio: audio
215-
};
216-
return this._asyncRecognize(req, options, callback);
208+
return this._asyncRecognize(request, options, callback);
217209
};
218210

219211
function SpeechApiBuilder(gaxGrpc) {

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,13 @@ describe('Speech', function() {
647647

648648
it('should make the correct request', function(done) {
649649
speech.api.Speech = {
650-
syncRecognize: function(config, file) {
650+
syncRecognize: function(reqOpts) {
651651
var expectedConfig = extend({}, CONFIG, {
652652
encoding: DETECTED_ENCODING
653653
});
654-
assert.deepEqual(config, expectedConfig);
655654

656-
assert.strictEqual(file, FOUND_FILE);
655+
assert.deepEqual(reqOpts.config, expectedConfig);
656+
assert.strictEqual(reqOpts.audio, FOUND_FILE);
657657

658658
done();
659659
}
@@ -672,8 +672,8 @@ describe('Speech', function() {
672672
};
673673

674674
speech.api.Speech = {
675-
syncRecognize: function(config_) {
676-
assert.strictEqual(config_.encoding, config.encoding);
675+
syncRecognize: function(reqOpts) {
676+
assert.strictEqual(reqOpts.config.encoding, config.encoding);
677677
done();
678678
}
679679
};
@@ -690,8 +690,8 @@ describe('Speech', function() {
690690
};
691691

692692
speech.api.Speech = {
693-
syncRecognize: function(config) {
694-
assert.strictEqual(config.encoding, expectedEncoding);
693+
syncRecognize: function(reqOpts) {
694+
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
695695
done();
696696
}
697697
};
@@ -718,7 +718,7 @@ describe('Speech', function() {
718718

719719
beforeEach(function() {
720720
speech.api.Speech = {
721-
syncRecognize: function(config, file, callback) {
721+
syncRecognize: function(reqOpts, callback) {
722722
callback(error, apiResponse);
723723
}
724724
};
@@ -757,7 +757,7 @@ describe('Speech', function() {
757757
};
758758

759759
speech.api.Speech = {
760-
syncRecognize: function(config, file, callback) {
760+
syncRecognize: function(reqOpts, callback) {
761761
callback(null, apiResponse);
762762
}
763763
};
@@ -815,8 +815,8 @@ describe('Speech', function() {
815815

816816
it('should delete verbose option from request object', function(done) {
817817
speech.api.Speech = {
818-
syncRecognize: function(config) {
819-
assert.strictEqual(config.verbose, undefined);
818+
syncRecognize: function(reqOpts) {
819+
assert.strictEqual(reqOpts.config.verbose, undefined);
820820
done();
821821
}
822822
};
@@ -861,13 +861,13 @@ describe('Speech', function() {
861861

862862
it('should make the correct request', function(done) {
863863
speech.api.Speech = {
864-
asyncRecognize: function(config, file) {
864+
asyncRecognize: function(reqOpts) {
865865
var expectedConfig = extend({}, CONFIG, {
866866
encoding: DETECTED_ENCODING
867867
});
868-
assert.deepEqual(config, expectedConfig);
869868

870-
assert.strictEqual(file, FOUND_FILE);
869+
assert.deepEqual(reqOpts.config, expectedConfig);
870+
assert.strictEqual(reqOpts.audio, FOUND_FILE);
871871

872872
done();
873873
}
@@ -886,8 +886,8 @@ describe('Speech', function() {
886886
};
887887

888888
speech.api.Speech = {
889-
asyncRecognize: function(config_) {
890-
assert.strictEqual(config_.encoding, config.encoding);
889+
asyncRecognize: function(reqOpts) {
890+
assert.strictEqual(reqOpts.config.encoding, config.encoding);
891891
done();
892892
}
893893
};
@@ -904,8 +904,8 @@ describe('Speech', function() {
904904
};
905905

906906
speech.api.Speech = {
907-
asyncRecognize: function(config) {
908-
assert.strictEqual(config.encoding, expectedEncoding);
907+
asyncRecognize: function(reqOpts) {
908+
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
909909
done();
910910
}
911911
};
@@ -932,7 +932,7 @@ describe('Speech', function() {
932932

933933
beforeEach(function() {
934934
speech.api.Speech = {
935-
asyncRecognize: function(config, file, callback) {
935+
asyncRecognize: function(reqOpts, callback) {
936936
callback(error, apiResponse);
937937
}
938938
};
@@ -978,7 +978,7 @@ describe('Speech', function() {
978978
};
979979

980980
speech.api.Speech = {
981-
asyncRecognize: function(config, file, callback) {
981+
asyncRecognize: function(reqOpts, callback) {
982982
callback(null, apiResponse);
983983
}
984984
};
@@ -1058,8 +1058,8 @@ describe('Speech', function() {
10581058

10591059
it('should delete verbose option from request object', function(done) {
10601060
speech.api.Speech = {
1061-
asyncRecognize: function(config) {
1062-
assert.strictEqual(config.verbose, undefined);
1061+
asyncRecognize: function(reqOpts) {
1062+
assert.strictEqual(reqOpts.config.verbose, undefined);
10631063
done();
10641064
}
10651065
};

0 commit comments

Comments
 (0)