diff --git a/packages/speech/src/index.js b/packages/speech/src/index.js index 790692d34f7..9421c5b635e 100644 --- a/packages/speech/src/index.js +++ b/packages/speech/src/index.js @@ -476,6 +476,10 @@ Speech.formatResults_ = function(resultSets, verboseMode) { Speech.prototype.createRecognizeStream = function(config) { var self = this; + if (!config) { + throw new Error('A recognize request requires a configuration object.'); + } + var verboseMode = config.verbose === true; delete config.verbose; @@ -650,6 +654,10 @@ Speech.prototype.operation = function(name) { Speech.prototype.recognize = function(file, config, callback) { var self = this; + if (!is.object(config)) { + throw new Error('A recognize request requires a configuration object.'); + } + config = extend({}, config); if (!config.encoding) { diff --git a/packages/speech/test/index.js b/packages/speech/test/index.js index 19c7655fd4f..b16e3bf6ad2 100644 --- a/packages/speech/test/index.js +++ b/packages/speech/test/index.js @@ -458,6 +458,12 @@ describe('Speech', function() { }; }); + it('should throw if an object is not provided', function() { + assert.throws(function() { + speech.createRecognizeStream(); + }, /A recognize request requires a configuration object\./); + }); + it('should make the correct request once writing started', function(done) { speech.api.Speech = { streamingRecognize: function() { @@ -684,6 +690,12 @@ describe('Speech', function() { }; }); + it('should throw if an object is not provided', function() { + assert.throws(function() { + speech.recognize(FILE, assert.ifError); + }, /A recognize request requires a configuration object\./); + }); + it('should find the files', function(done) { Speech.findFile_ = function(file) { assert.strictEqual(file, FILE);