@@ -26,7 +26,7 @@ const http = require('http');
26
26
const isStream = require ( 'isstream' ) ;
27
27
const requestFactory = require ( '../lib/requestwrapper' ) ;
28
28
const RecognizeStream = require ( './recognize_stream' ) ;
29
- const pkg = require ( '../package.json' ) ; // todo: consider using env properties here instead (to enable webpack support without requiring a plugin)
29
+ const pkg = require ( '../package.json' ) ;
30
30
const util = require ( 'util' ) ;
31
31
const BaseService = require ( '../lib/base_service' ) ;
32
32
const async = require ( 'async' ) ;
@@ -38,7 +38,7 @@ const PARAMS_ALLOWED = [
38
38
'word_confidence' ,
39
39
'inactivity_timeout' ,
40
40
'model' ,
41
- 'content-type' ,
41
+ 'content-type' , // this is accepted in querystring by the service, but methods here all accept content_type and then set a header
42
42
'interim_results' ,
43
43
'keywords' ,
44
44
'keywords_threshold' ,
@@ -128,12 +128,13 @@ SpeechToTextV1.prototype.registerCallback = function(params, callback) {
128
128
* How you learn the status and results of a job depends on the parameters you include with the job creation request.
129
129
*
130
130
* @param {object } params - The parameters
131
- * @param {Audio } params.audio - Audio to be recognized
131
+ * @param {Stream } params.audio - Audio to be recognized
132
132
* @param {string } params.content_type - The Content-type e.g. audio/l16; rate=48000
133
133
* @param {string } params.callback_url - A URL to which callback notifications are to be sent
134
134
* @param {string } [params.event] - recognitions.started|recognitions.completed|recognitions.failed|recognitions.completed_with_results
135
135
* @param {string } [params.user_token] - The token allows the user to maintain an internal mapping between jobs and notification events
136
136
* @param {number } [params.results_ttl] - time to alive of the job result
137
+ * @param {* } [params.*] - all params that .recognize() accepts may also be passed to createRecognitionJob()
137
138
* @param {Function } callback
138
139
* @returns {ReadableStream|undefined }
139
140
*/
@@ -156,7 +157,7 @@ SpeechToTextV1.prototype.createRecognitionJob = function(params, callback) {
156
157
headers : {
157
158
'Content-Type' : params . content_type
158
159
} ,
159
- qs : pick ( params , [ 'callback_url' , 'event' , 'user_token' , 'results_ttl' ] ) ,
160
+ qs : pick ( params , [ 'callback_url' , 'event' , 'user_token' , 'results_ttl' ] . concat ( PARAMS_ALLOWED ) ) ,
160
161
json : true
161
162
} ,
162
163
defaultOptions : this . _options
@@ -175,10 +176,14 @@ SpeechToTextV1.prototype.createRecognitionJob = function(params, callback) {
175
176
* The method also returns the creation and update times of each job, and, if a job was created with a callback URL
176
177
* and a user token, the user token for the job.
177
178
*
179
+ * @param {Object } [params]
178
180
* @param {Function } callback
179
181
* @returns {ReadableStream|undefined }
180
182
*/
181
- SpeechToTextV1 . prototype . getRecognitionJobs = function ( callback ) {
183
+ SpeechToTextV1 . prototype . getRecognitionJobs = function ( params , callback ) {
184
+ if ( ! callback && typeof params === 'function' ) {
185
+ callback = params ;
186
+ }
182
187
const parameters = {
183
188
options : {
184
189
method : 'GET' ,
@@ -251,8 +256,23 @@ SpeechToTextV1.prototype.deleteRecognitionJob = function(params, callback) {
251
256
* Speech recognition for given audio using default model.
252
257
*
253
258
* @param {Object } params The parameters
254
- * @param {Audio } [params.audio] - Audio to be recognized
255
- * @param {String } [params.content_type] - Content-type
259
+ * @param {Stream } params.audio - Audio to be recognized
260
+ * @param {String } params.content_type - Content-type
261
+ * @param {Boolean } [params.continuous],
262
+ * @param {Number } [params.max_alternatives],
263
+ * @param {Boolean } [params.timestamps],
264
+ * @param {Boolean } [params.word_confidence],
265
+ * @param {Number } [params.inactivity_timeout],
266
+ * @param {String } [params.model],
267
+ * @param {Boolean } [params.interim_results],
268
+ * @param {Boolean } [params.keywords],
269
+ * @param {Number } [params.keywords_threshold],
270
+ * @param {Number } [params.word_alternatives_threshold],
271
+ * @param {Boolean } [params.profanity_filter],
272
+ * @param {Boolean } [params.smart_formatting],
273
+ * @param {String } [params.customization_id],
274
+ * @param {Boolean } [params.speaker_labels]
275
+ * @param {function } callback
256
276
*/
257
277
SpeechToTextV1 . prototype . recognize = function ( params , callback ) {
258
278
const missingParams = helper . getMissingParams ( params , [ 'audio' , 'content_type' ] ) ;
@@ -299,10 +319,12 @@ SpeechToTextV1.prototype.recognize = function(params, callback) {
299
319
* Sets 'Transfer-Encoding': 'chunked' and prepare the connection to send
300
320
* chunk data.
301
321
*
322
+ * @deprecated use createRecognizeStream instead
323
+ *
302
324
* @param {Object } params The parameters
303
325
* @param {String } [params.content_type] - The Content-type e.g. audio/l16; rate=48000
304
326
* @param {String } [params.session_id] - The session id
305
- * @deprecated use createRecognizeStream instead
327
+ * @param { function } callback
306
328
*/
307
329
SpeechToTextV1 . prototype . recognizeLive = function ( params , callback ) {
308
330
const missingParams = helper . getMissingParams ( params , [ 'session_id' , 'content_type' , 'cookie_session' ] ) ;
@@ -360,10 +382,12 @@ SpeechToTextV1.prototype.recognizeLive = function(params, callback) {
360
382
* This request has to be started before POST on recognize finishes,
361
383
* otherwise it waits for the next recognition.
362
384
*
385
+ * @deprecated use createRecognizeStream instead
386
+ *
363
387
* @param {Object } params The parameters
364
388
* @param {String } [params.session_id] - Session used in the recognition
365
389
* @param {boolean } [params.interim_results] - If true, interim results will be returned. Default: false
366
- * @deprecated use createRecognizeStream instead
390
+ * @param { Function } callback
367
391
*/
368
392
SpeechToTextV1 . prototype . observeResult = function ( params , callback ) {
369
393
const missingParams = helper . getMissingParams ( params , [ 'session_id' , 'cookie_session' ] ) ;
@@ -415,9 +439,11 @@ SpeechToTextV1.prototype.observeResult = function(params, callback) {
415
439
* This is the way to check if the session is ready to accept a new recognition task.
416
440
* The returned state has to be 'initialized' to be able to do recognize POST.
417
441
*
442
+ * @deprecated use createRecognizeStream instead
443
+ *
418
444
* @param {Object } params The parameters
419
445
* @param {String } [params.session_id] - Session used in the recognition
420
- * @deprecated use createRecognizeStream instead
446
+ * @param { Function } callback
421
447
*/
422
448
SpeechToTextV1 . prototype . getRecognizeStatus = function ( params , callback ) {
423
449
const parameters = {
@@ -482,6 +508,7 @@ SpeechToTextV1.prototype.getModel = function(params, callback) {
482
508
*
483
509
* @param {Object } params The parameters
484
510
* @param {string } params.model - The model to use during the session
511
+ * @param {Function } callback
485
512
*/
486
513
SpeechToTextV1 . prototype . createSession = function ( params , callback ) {
487
514
const parameters = {
@@ -520,6 +547,7 @@ SpeechToTextV1.prototype.createSession = function(params, callback) {
520
547
*
521
548
* @param {Object } params The parameters
522
549
* @param {String } params.session_id - Session id.
550
+ * @param {Function } callback
523
551
*/
524
552
SpeechToTextV1 . prototype . deleteSession = function ( params , callback ) {
525
553
const parameters = {
0 commit comments