Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring Speech API samples up to standard. #362

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions speech/recognize.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ function streamingRecognize (filename, encoding, sampleRateHertz, languageCode)
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
}
},
interimResults: false // If you want interim results, set this to true
};

// Stream the audio to the Google Cloud Speech API
Expand Down Expand Up @@ -255,7 +256,8 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
}
},
interimResults: false // If you want interim results, set this to true
};

// Create a recognize stream
Expand All @@ -264,16 +266,23 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) {
.on('data', (data) => process.stdout.write(data.results));

// Start recording and send the microphone input to the Speech API
record.start({
sampleRateHertz: sampleRateHertz,
threshold: 0
}).pipe(recognizeStream);
record
.start({
sampleRateHertz: sampleRateHertz,
threshold: 0,
// Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
verbose: false,
recordProgram: 'rec', // Try also "arecord" or "sox"
silence: '10.0'
})
.on('error', console.error)
.pipe(recognizeStream);

console.log('Listening, press Ctrl+C to stop.');
// [END speech_streaming_mic_recognize]
}

require(`yargs`) // eslint-disable-line
const cli = require(`yargs`)
.demand(1)
.command(
`sync <filename>`,
Expand Down Expand Up @@ -342,5 +351,8 @@ require(`yargs`) // eslint-disable-line
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/speech/docs`)
.help()
.strict()
.argv;
.strict();

if (module === require.main) {
cli.parse(process.argv.slice(2));
}