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

Added enableWordTimeOffsets: true to async (file) #440

Merged
merged 4 commits into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions speech/recognize.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function syncRecognize (filename, encoding, sampleRateHertz, languageCode) {
// const languageCode = 'en-US';

const config = {
enableWordTimeOffsets: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We prefer not to set optional fields to their default values in the samples.

encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
Expand Down Expand Up @@ -91,6 +92,7 @@ function syncRecognizeGCS (gcsUri, encoding, sampleRateHertz, languageCode) {
// const languageCode = 'en-US';

const config = {
enableWordTimeOffsets: false,
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
Expand Down Expand Up @@ -138,6 +140,7 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) {
// const languageCode = 'en-US';

const config = {
enableWordTimeOffsets: true,
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
Expand All @@ -162,6 +165,16 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) {
.then((results) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this variable to something different (e.g response) to avoid the confusing naming, both here and in the other examples.

const transcription = results[0].results[0].alternatives[0].transcript;
console.log(`Transcription: ${transcription}`);
results[0].results[0].alternatives[0].words.forEach((wordInfo) => {
// NOTE: If you have a time offset exceeding 2^32 seconds, use the
// wordInfo.{x}Time.seconds.high to calculate seconds.
let startSecs = `${wordInfo.startTime.seconds.low}` + `.` +
(wordInfo.startTime.nanos / 100000000);
let endSecs = `${wordInfo.endTime.seconds.low}` + `.` +
(wordInfo.endTime.nanos / 100000000);
console.log(`Word: ${wordInfo.word}`);
console.log(`\t ${startSecs} secs - ${endSecs} secs`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to update the test for this method, similar to what was done here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});
})
.catch((err) => {
console.error('ERROR:', err);
Expand Down
2 changes: 2 additions & 0 deletions speech/system-test/recognize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ test(`should run sync recognize on a GCS file`, async (t) => {
test(`should run async recognize on a local file`, async (t) => {
const output = await runAsync(`${cmd} async ${filepath}`, cwd);
t.true(output.includes(`Transcription: ${text}`));
// Check for word time offsets
t.true(new RegExp(`\\d+\\.\\d+ secs - \\d+\\.\\d+ secs`).test(output));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdobry added the missing test

});

test(`should run async recognize on a GCS file`, async (t) => {
Expand Down