@@ -45,6 +45,7 @@ function syncRecognize (filename, encoding, sampleRateHertz, languageCode) {
4545 // const languageCode = 'en-US';
4646
4747 const config = {
48+ enableWordTimeOffsets : false ,
4849 encoding : encoding ,
4950 sampleRateHertz : sampleRateHertz ,
5051 languageCode : languageCode
@@ -91,6 +92,7 @@ function syncRecognizeGCS (gcsUri, encoding, sampleRateHertz, languageCode) {
9192 // const languageCode = 'en-US';
9293
9394 const config = {
95+ enableWordTimeOffsets : false ,
9496 encoding : encoding ,
9597 sampleRateHertz : sampleRateHertz ,
9698 languageCode : languageCode
@@ -138,6 +140,7 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) {
138140 // const languageCode = 'en-US';
139141
140142 const config = {
143+ enableWordTimeOffsets : true ,
141144 encoding : encoding ,
142145 sampleRateHertz : sampleRateHertz ,
143146 languageCode : languageCode
@@ -162,6 +165,16 @@ function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) {
162165 . then ( ( results ) => {
163166 const transcription = results [ 0 ] . results [ 0 ] . alternatives [ 0 ] . transcript ;
164167 console . log ( `Transcription: ${ transcription } ` ) ;
168+ results [ 0 ] . results [ 0 ] . alternatives [ 0 ] . words . forEach ( ( wordInfo ) => {
169+ // NOTE: If you have a time offset exceeding 2^32 seconds, use the
170+ // wordInfo.{x}Time.seconds.high to calculate seconds.
171+ let startSecs = `${ wordInfo . startTime . seconds . low } ` + `.` +
172+ ( wordInfo . startTime . nanos / 100000000 ) ;
173+ let endSecs = `${ wordInfo . endTime . seconds . low } ` + `.` +
174+ ( wordInfo . endTime . nanos / 100000000 ) ;
175+ console . log ( `Word: ${ wordInfo . word } ` ) ;
176+ console . log ( `\t ${ startSecs } secs - ${ endSecs } secs` ) ;
177+ } ) ;
165178 } )
166179 . catch ( ( err ) => {
167180 console . error ( 'ERROR:' , err ) ;
0 commit comments