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: update gapic layer #1737

Merged
merged 1 commit into from
Oct 21, 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
2 changes: 1 addition & 1 deletion packages/speech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@google-cloud/common": "^0.7.0",
"events-intercept": "^2.0.0",
"extend": "^3.0.0",
"google-gax": "^0.7.0",
"google-gax": "^0.8.1",
"google-proto-files": "^0.8.0",
"is": "^3.1.0",
"modelo": "^4.2.0",
Expand Down
10 changes: 8 additions & 2 deletions packages/speech/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ Speech.prototype.recognize = function(file, config, callback) {
return;
}

self.api.Speech.syncRecognize(config, foundFile, function(err, resp) {
self.api.Speech.syncRecognize({
config: config,
audio: foundFile
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -799,7 +802,10 @@ Speech.prototype.startRecognition = function(file, config, callback) {
return;
}

self.api.Speech.asyncRecognize(config, foundFile, function(err, resp) {
self.api.Speech.asyncRecognize({
config: config,
audio: foundFile
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down
68 changes: 30 additions & 38 deletions packages/speech/src/v1beta1/speech_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
* Perform synchronous speech-recognition: receive results after all audio
* has been sent and processed.
*
* @param {Object} config
* @param {Object} request
* The request object that will be sent.
* @param {Object} request.config
* [Required] The `config` message provides information to the recognizer
* that specifies how to process the request.
*
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
* @param {Object} audio
* @param {Object} request.audio
* [Required] The audio data to be recognized.
*
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
Expand All @@ -124,39 +126,33 @@ function SpeechApi(gaxGrpc, grpcClients, opts) {
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [SyncRecognizeResponse]{@link SyncRecognizeResponse}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
* @returns {Promise} - The promise which resolves to the response object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var api = speechV1beta1.speechApi();
* var config = {};
* var audio = {};
* api.syncRecognize(config, audio, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* var request = {
* config: config,
* audio: audio
* };
* api.syncRecognize(request).then(function(response) {
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
SpeechApi.prototype.syncRecognize = function syncRecognize(
config,
audio,
options,
callback) {
SpeechApi.prototype.syncRecognize = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
var req = {
config: config,
audio: audio
};
return this._syncRecognize(req, options, callback);
return this._syncRecognize(request, options, callback);
};

/**
Expand All @@ -165,12 +161,14 @@ SpeechApi.prototype.syncRecognize = function syncRecognize(
* `Operation.error` or an `Operation.response` which contains
* an `AsyncRecognizeResponse` message.
*
* @param {Object} config
* @param {Object} request
* The request object that will be sent.
* @param {Object} request.config
* [Required] The `config` message provides information to the recognizer
* that specifies how to process the request.
*
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
* @param {Object} audio
* @param {Object} request.audio
* [Required] The audio data to be recognized.
*
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
Expand All @@ -181,39 +179,33 @@ SpeechApi.prototype.syncRecognize = function syncRecognize(
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [google.longrunning.Operation]{@link external:"google.longrunning.Operation"}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
* @returns {Promise} - The promise which resolves to the response object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var api = speechV1beta1.speechApi();
* var config = {};
* var audio = {};
* api.asyncRecognize(config, audio, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* var request = {
* config: config,
* audio: audio
* };
* api.asyncRecognize(request).then(function(response) {
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
SpeechApi.prototype.asyncRecognize = function asyncRecognize(
config,
audio,
options,
callback) {
SpeechApi.prototype.asyncRecognize = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
var req = {
config: config,
audio: audio
};
return this._asyncRecognize(req, options, callback);
return this._asyncRecognize(request, options, callback);
};

function SpeechApiBuilder(gaxGrpc) {
Expand Down
44 changes: 22 additions & 22 deletions packages/speech/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,13 @@ describe('Speech', function() {

it('should make the correct request', function(done) {
speech.api.Speech = {
syncRecognize: function(config, file) {
syncRecognize: function(reqOpts) {
var expectedConfig = extend({}, CONFIG, {
encoding: DETECTED_ENCODING
});
assert.deepEqual(config, expectedConfig);

assert.strictEqual(file, FOUND_FILE);
assert.deepEqual(reqOpts.config, expectedConfig);
assert.strictEqual(reqOpts.audio, FOUND_FILE);

done();
}
Expand All @@ -672,8 +672,8 @@ describe('Speech', function() {
};

speech.api.Speech = {
syncRecognize: function(config_) {
assert.strictEqual(config_.encoding, config.encoding);
syncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.encoding, config.encoding);
done();
}
};
Expand All @@ -690,8 +690,8 @@ describe('Speech', function() {
};

speech.api.Speech = {
syncRecognize: function(config) {
assert.strictEqual(config.encoding, expectedEncoding);
syncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
done();
}
};
Expand All @@ -718,7 +718,7 @@ describe('Speech', function() {

beforeEach(function() {
speech.api.Speech = {
syncRecognize: function(config, file, callback) {
syncRecognize: function(reqOpts, callback) {
callback(error, apiResponse);
}
};
Expand Down Expand Up @@ -757,7 +757,7 @@ describe('Speech', function() {
};

speech.api.Speech = {
syncRecognize: function(config, file, callback) {
syncRecognize: function(reqOpts, callback) {
callback(null, apiResponse);
}
};
Expand Down Expand Up @@ -815,8 +815,8 @@ describe('Speech', function() {

it('should delete verbose option from request object', function(done) {
speech.api.Speech = {
syncRecognize: function(config) {
assert.strictEqual(config.verbose, undefined);
syncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.verbose, undefined);
done();
}
};
Expand Down Expand Up @@ -861,13 +861,13 @@ describe('Speech', function() {

it('should make the correct request', function(done) {
speech.api.Speech = {
asyncRecognize: function(config, file) {
asyncRecognize: function(reqOpts) {
var expectedConfig = extend({}, CONFIG, {
encoding: DETECTED_ENCODING
});
assert.deepEqual(config, expectedConfig);

assert.strictEqual(file, FOUND_FILE);
assert.deepEqual(reqOpts.config, expectedConfig);
assert.strictEqual(reqOpts.audio, FOUND_FILE);

done();
}
Expand All @@ -886,8 +886,8 @@ describe('Speech', function() {
};

speech.api.Speech = {
asyncRecognize: function(config_) {
assert.strictEqual(config_.encoding, config.encoding);
asyncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.encoding, config.encoding);
done();
}
};
Expand All @@ -904,8 +904,8 @@ describe('Speech', function() {
};

speech.api.Speech = {
asyncRecognize: function(config) {
assert.strictEqual(config.encoding, expectedEncoding);
asyncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
done();
}
};
Expand All @@ -932,7 +932,7 @@ describe('Speech', function() {

beforeEach(function() {
speech.api.Speech = {
asyncRecognize: function(config, file, callback) {
asyncRecognize: function(reqOpts, callback) {
callback(error, apiResponse);
}
};
Expand Down Expand Up @@ -978,7 +978,7 @@ describe('Speech', function() {
};

speech.api.Speech = {
asyncRecognize: function(config, file, callback) {
asyncRecognize: function(reqOpts, callback) {
callback(null, apiResponse);
}
};
Expand Down Expand Up @@ -1058,8 +1058,8 @@ describe('Speech', function() {

it('should delete verbose option from request object', function(done) {
speech.api.Speech = {
asyncRecognize: function(config) {
assert.strictEqual(config.verbose, undefined);
asyncRecognize: function(reqOpts) {
assert.strictEqual(reqOpts.config.verbose, undefined);
done();
}
};
Expand Down