Skip to content

Commit 3f97b80

Browse files
committed
fix: fix bug that prevents audio from being sent as a buffer for recognize
now using the generated method for recognize. providing a better error message for when streams are used without providing `content_type`
1 parent 25aec3d commit 3f97b80

File tree

1 file changed

+3
-66
lines changed

1 file changed

+3
-66
lines changed

speech-to-text/v1.ts

+3-66
Original file line numberDiff line numberDiff line change
@@ -483,76 +483,13 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
483483
return new RecognizeStream(params);
484484
}
485485

486-
/**
487-
* Speech recognition for given audio using default model.
488-
*
489-
* @param {Object} params The parameters
490-
* @param {Stream} params.audio - Audio to be recognized
491-
* @param {String} [params.content_type] - Content-type
492-
* @param {String} [params.base_model_version]
493-
* @param {Number} [params.max_alternatives]
494-
* @param {Boolean} [params.timestamps]
495-
* @param {Boolean} [params.word_confidence]
496-
* @param {Number} [params.inactivity_timeout]
497-
* @param {String} [params.model]
498-
* @param {Boolean} [params.interim_results]
499-
* @param {Boolean} [params.keywords]
500-
* @param {Number} [params.keywords_threshold]
501-
* @param {Number} [params.word_alternatives_threshold]
502-
* @param {Boolean} [params.profanity_filter]
503-
* @param {Boolean} [params.smart_formatting]
504-
* @param {String} [params.language_customization_id]
505-
* @param {String} [params.customization_id]
506-
* @param {String} [params.acoustic_customization_id]
507-
* @param {Number} [params.customization_weight]
508-
* @param {Boolean} [params.speaker_labels]
509-
* @param {function} callback
510-
*/
511486
recognize(params, callback) {
512-
const missingParams = getMissingParams(params, ['audio']);
513-
if (missingParams) {
514-
callback(missingParams);
515-
return;
516-
}
517-
if (!isStream(params.audio)) {
518-
callback(new Error('audio is not a standard Node.js Stream'));
487+
if (isStream(params.audio) && !params.content_type) {
488+
callback(new Error('If providing `audio` as a Stream, `content_type` is required.'));
519489
return;
520490
}
521491

522-
const queryParams = pick(params, PARAMS_ALLOWED);
523-
if (Array.isArray(queryParams.keywords)) {
524-
queryParams.keywords = queryParams.keywords.join(',');
525-
}
526-
527-
let _url = '/v1';
528-
_url += params.session_id ? '/sessions/' + params.session_id : '';
529-
_url += '/recognize';
530-
531-
const parameters = {
532-
options: {
533-
method: 'POST',
534-
url: _url,
535-
json: true,
536-
qs: queryParams
537-
},
538-
defaultOptions: extend(true, {}, this._options, {
539-
headers: {
540-
'Content-Type': params.content_type
541-
}
542-
})
543-
};
544-
545-
this.preAuthenticate((err) => {
546-
if (err) {
547-
return err;
548-
}
549-
return params.audio
550-
.on('response', (response) => {
551-
// Replace content-type
552-
response.headers['content-type'] = params.content_type;
553-
})
554-
.pipe(this.createRequest(parameters, callback));
555-
});
492+
return super.recognize(params, callback);
556493
}
557494

558495
deleteCustomization(params, callback) {

0 commit comments

Comments
 (0)