-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ function syncRecognize (filename, encoding, sampleRateHertz, languageCode) { | |
// const languageCode = 'en-US'; | ||
|
||
const config = { | ||
enableWordTimeOffsets: false, | ||
encoding: encoding, | ||
sampleRateHertz: sampleRateHertz, | ||
languageCode: languageCode | ||
|
@@ -91,6 +92,7 @@ function syncRecognizeGCS (gcsUri, encoding, sampleRateHertz, languageCode) { | |
// const languageCode = 'en-US'; | ||
|
||
const config = { | ||
enableWordTimeOffsets: false, | ||
encoding: encoding, | ||
sampleRateHertz: sampleRateHertz, | ||
languageCode: languageCode | ||
|
@@ -138,6 +140,7 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) { | |
// const languageCode = 'en-US'; | ||
|
||
const config = { | ||
enableWordTimeOffsets: true, | ||
encoding: encoding, | ||
sampleRateHertz: sampleRateHertz, | ||
languageCode: languageCode | ||
|
@@ -162,6 +165,16 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) { | |
.then((results) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}); | ||
}) | ||
.catch((err) => { | ||
console.error('ERROR:', err); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
|
There was a problem hiding this comment.
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.