@@ -22,6 +22,7 @@ var util = require('util');
2222var pick = require ( 'object.pick' ) ;
2323var W3CWebSocket = require ( 'websocket' ) . w3cwebsocket ;
2424var contentType = require ( './content-type' ) ;
25+ var defaults = require ( 'defaults' ) ;
2526
2627
2728var OPENING_MESSAGE_PARAMS_ALLOWED = [ 'continuous' , 'max_alternatives' , 'timestamps' , 'word_confidence' , 'inactivity_timeout' ,
@@ -103,7 +104,11 @@ RecognizeStream.prototype.initialize = function () {
103104 var url = ( options . url || "wss://stream.watsonplatform.net/speech-to-text/api" ) . replace ( / ^ h t t p / , 'ws' ) + '/v1/recognize?' + queryString ;
104105
105106 // turn off all the extras if we're just outputting text
106- var defaults = {
107+ var textModeDefaults = {
108+ action : 'start' ,
109+ 'content-type' : 'audio/wav' ,
110+ continuous : true ,
111+ inactivity_timeout : 30 ,
107112 interim_results : false ,
108113 word_confidence : false ,
109114 timestamps : false ,
@@ -112,24 +117,21 @@ RecognizeStream.prototype.initialize = function () {
112117
113118 // but turn everything on if we're in objectMode and the end user can consume it
114119 var objectModeDefaults = {
120+ action : 'start' ,
121+ 'content-type' : 'audio/wav' ,
122+ continuous : true ,
123+ inactivity_timeout : 30 ,
115124 interim_results : true ,
116125 word_confidence : true ,
117126 timestamps : true ,
118127 max_alternatives : 3
119128 } ;
120129
121- var openingMessage = util . _extend ( {
122- action : 'start' ,
123- 'content-type' : 'audio/wav' ,
124- continuous : true ,
125- max_alternatives : 3 ,
126- inactivity_timeout : 30
127- } ,
128- ( options . objectMode || options . readableObjectMode ) ? objectModeDefaults : defaults ,
129- pick ( options , OPENING_MESSAGE_PARAMS_ALLOWED )
130+ var openingMessage = defaults (
131+ pick ( options , OPENING_MESSAGE_PARAMS_ALLOWED ) ,
132+ ( options . objectMode || options . readableObjectMode ) ? objectModeDefaults : textModeDefaults
130133 ) ;
131134
132-
133135 var self = this ;
134136
135137 //node params: requestUrl, protocols, origin, headers, extraRequestOptions
0 commit comments