1- var fs = require ( 'fs' ) ;
1+ 'use strict' ;
2+ const fs = require ( 'fs' ) ;
23require ( 'dotenv' ) . config ( { silent : true } ) ; // optional, handy for local development
3- var SpeechToText = require ( 'watson-developer-cloud/speech-to-text/v1' ) ;
4- var mic = require ( 'mic' ) ;
5- var wav = require ( 'wav' ) ;
6-
7-
8- var speechToText = new SpeechToText ( {
9- // if left unspecified here, the SDK will fall back to the SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD
10- // environment properties, and then Bluemix's VCAP_SERVICES environment property
11- // username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
12- // password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
13- } ) ;
14-
15- var micInstance = mic ( {
16- 'rate' : '48000' ,
17- 'channels' : '1' ,
18- 'debug' : false
4+ const SpeechToText = require ( 'watson-developer-cloud/speech-to-text/v1' ) ;
5+ const mic = require ( 'mic' ) ;
6+ const wav = require ( 'wav' ) ;
7+
8+ const speechToText = new SpeechToText (
9+ {
10+ // if left unspecified here, the SDK will fall back to the SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD
11+ // environment properties, and then Bluemix's VCAP_SERVICES environment property
12+ // username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
13+ // password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
14+ }
15+ ) ;
16+
17+ const micInstance = mic ( {
18+ rate : '48000' ,
19+ channels : '1' ,
20+ debug : false
1921} ) ;
2022
21- var micInputStream = micInstance . getAudioStream ( ) ;
22-
23+ const micInputStream = micInstance . getAudioStream ( ) ;
2324
24- var wavStream = new wav . FileWriter ( './audio.wav' , {
25+ const wavStream = new wav . FileWriter ( './audio.wav' , {
2526 sampleRate : 48000 ,
2627 channels : 1
2728} ) ;
2829
29- var recognizeStream = speechToText . createRecognizeStream ( { ' content_type' : 'audio/wav' } ) ;
30+ const recognizeStream = speechToText . createRecognizeStream ( { content_type : 'audio/wav' } ) ;
3031
3132micInputStream . pipe ( wavStream ) ;
3233
@@ -48,8 +49,7 @@ process.stdin.once('data', function() {
4849 micInstance . stop ( ) ;
4950 recognizeStream . on ( 'end' , function ( ) {
5051 process . exit ( ) ;
51- } )
52+ } ) ;
5253} ) ;
5354
54-
5555micInstance . start ( ) ;
0 commit comments