@@ -216,7 +216,8 @@ function streamingRecognize (filename, encoding, sampleRateHertz, languageCode)
216
216
encoding : encoding ,
217
217
sampleRateHertz : sampleRateHertz ,
218
218
languageCode : languageCode
219
- }
219
+ } ,
220
+ interimResults : false // If you want interim results, set this to true
220
221
} ;
221
222
222
223
// Stream the audio to the Google Cloud Speech API
@@ -255,7 +256,8 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) {
255
256
encoding : encoding ,
256
257
sampleRateHertz : sampleRateHertz ,
257
258
languageCode : languageCode
258
- }
259
+ } ,
260
+ interimResults : false // If you want interim results, set this to true
259
261
} ;
260
262
261
263
// Create a recognize stream
@@ -264,16 +266,23 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) {
264
266
. on ( 'data' , ( data ) => process . stdout . write ( data . results ) ) ;
265
267
266
268
// Start recording and send the microphone input to the Speech API
267
- record . start ( {
268
- sampleRateHertz : sampleRateHertz ,
269
- threshold : 0
270
- } ) . pipe ( recognizeStream ) ;
269
+ record
270
+ . start ( {
271
+ sampleRateHertz : sampleRateHertz ,
272
+ threshold : 0 ,
273
+ // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
274
+ verbose : false ,
275
+ recordProgram : 'rec' , // Try also "arecord" or "sox"
276
+ silence : '10.0'
277
+ } )
278
+ . on ( 'error' , console . error )
279
+ . pipe ( recognizeStream ) ;
271
280
272
281
console . log ( 'Listening, press Ctrl+C to stop.' ) ;
273
282
// [END speech_streaming_mic_recognize]
274
283
}
275
284
276
- require ( `yargs` ) // eslint-disable-line
285
+ const cli = require ( `yargs` )
277
286
. demand ( 1 )
278
287
. command (
279
288
`sync <filename>` ,
@@ -342,5 +351,8 @@ require(`yargs`) // eslint-disable-line
342
351
. recommendCommands ( )
343
352
. epilogue ( `For more information, see https://cloud.google.com/speech/docs` )
344
353
. help ( )
345
- . strict ( )
346
- . argv ;
354
+ . strict ( ) ;
355
+
356
+ if ( module === require . main ) {
357
+ cli . parse ( process . argv . slice ( 2 ) ) ;
358
+ }
0 commit comments