@@ -124,7 +124,6 @@ RecognizeStream.WEBSOCKET_CONNECTION_ERROR = 'WebSocket connection error';
124124RecognizeStream . prototype . initialize = function ( ) {
125125 var options = this . options ;
126126
127- // todo: apply these corrections to other methods (?)
128127 if ( options . token && ! options [ 'watson-token' ] ) {
129128 options [ 'watson-token' ] = options . token ;
130129 }
@@ -135,7 +134,10 @@ RecognizeStream.prototype.initialize = function() {
135134 options [ 'X-Watson-Learning-Opt-Out' ] = options [ 'X-WDC-PL-OPT-OUT' ] ;
136135 }
137136
138- var queryParams = util . _extend ( 'customization_id' in options ? pick ( options , QUERY_PARAMS_ALLOWED ) : { model : 'en-US_BroadbandModel' } , pick ( options , QUERY_PARAMS_ALLOWED ) ) ;
137+ var queryParams = util . _extend (
138+ 'customization_id' in options ? pick ( options , QUERY_PARAMS_ALLOWED ) : { model : 'en-US_BroadbandModel' } ,
139+ pick ( options , QUERY_PARAMS_ALLOWED )
140+ ) ;
139141
140142 var queryString = qs . stringify ( queryParams ) ;
141143 var url = ( options . url || 'wss://stream.watsonplatform.net/speech-to-text/api' ) . replace ( / ^ h t t p / , 'ws' ) + '/v1/recognize?' + queryString ;
@@ -329,8 +331,24 @@ RecognizeStream.prototype._write = function(chunk, encoding, callback) {
329331 }
330332} ;
331333
332- // flow control - don't ask for more data until we've finished what we have
333- // todo: see if this can be improved
334+ /**
335+ * Flow control - don't ask for more data until we've finished what we have
336+ *
337+ * Notes:
338+ *
339+ * This limits upload speed to 100 * options.highWaterMark / second.
340+ *
341+ * The default highWaterMark is 16kb, so the default max upload speed is ~1.6mb/s.
342+ *
343+ * Microphone input provides audio at a (downsampled) rate of:
344+ * 16000 samples/s * 16-bits * 1 channel = 31.25kb/s
345+ * (note the bits to bytes conversion there)
346+ *
347+ * @private
348+ * @param next
349+ */
350+ //
351+
334352RecognizeStream . prototype . afterSend = function afterSend ( next ) {
335353 if ( this . socket . bufferedAmount <= ( this . _writableState . highWaterMark || 0 ) ) {
336354 process . nextTick ( next ) ;
0 commit comments