@@ -169,26 +169,23 @@ SpeakerStream.prototype.buildMessage = function() {
169169 } ) ;
170170
171171 // group the words together into utterances by speaker
172- var utterances = words . reduce (
173- function ( arr , word ) {
174- var utterance = arr [ arr . length - 1 ] ;
175- // any time the speaker changes or the (original) result changes, create a new utterance
176- if ( ! utterance || utterance . speaker !== word . speaker || utterance . result !== word . result ) {
177- utterance = {
178- speaker : word . speaker ,
179- timestamps : [ word . timestamp ] ,
180- result : word . result
181- } ;
182- // and add it to the list
183- arr . push ( utterance ) ;
184- } else {
185- // otherwise just append the current word to the current result
186- utterance . timestamps . push ( word . timestamp ) ;
187- }
188- return arr ;
189- } ,
190- [ ]
191- ) ;
172+ var utterances = words . reduce ( function ( arr , word ) {
173+ var utterance = arr [ arr . length - 1 ] ;
174+ // any time the speaker changes or the (original) result changes, create a new utterance
175+ if ( ! utterance || utterance . speaker !== word . speaker || utterance . result !== word . result ) {
176+ utterance = {
177+ speaker : word . speaker ,
178+ timestamps : [ word . timestamp ] ,
179+ result : word . result
180+ } ;
181+ // and add it to the list
182+ arr . push ( utterance ) ;
183+ } else {
184+ // otherwise just append the current word to the current result
185+ utterance . timestamps . push ( word . timestamp ) ;
186+ }
187+ return arr ;
188+ } , [ ] ) ;
192189
193190 // create new results
194191 var results = utterances . map ( function ( utterance , i ) {
@@ -207,11 +204,12 @@ SpeakerStream.prototype.buildMessage = function() {
207204 result . speaker = utterance . speaker ;
208205 // overwrite the transcript and timestamps on the first alternative
209206 var alt = result . alternatives [ 0 ] ;
210- alt . transcript = utterance . timestamps
211- . map ( function ( ts ) {
212- return ts [ WORD ] ;
213- } )
214- . join ( ' ' ) + ' ' ;
207+ alt . transcript =
208+ utterance . timestamps
209+ . map ( function ( ts ) {
210+ return ts [ WORD ] ;
211+ } )
212+ . join ( ' ' ) + ' ' ;
215213 alt . timestamps = utterance . timestamps ;
216214 // overwrite the final value
217215 result . final = final ;
@@ -266,12 +264,9 @@ SpeakerStream.prototype.handleResults = function(data) {
266264 . filter ( function ( result ) {
267265 return result . final ;
268266 } )
269- . forEach (
270- function ( result ) {
271- this . results . push ( result ) ;
272- } ,
273- this
274- ) ;
267+ . forEach ( function ( result ) {
268+ this . results . push ( result ) ;
269+ } , this ) ;
275270} ;
276271
277272// sorts by start time and then end time
@@ -350,18 +345,16 @@ SpeakerStream.prototype._flush = function(done) {
350345 . map ( function ( r ) {
351346 return r . alternatives [ 0 ] . timestamps ;
352347 } )
353- . reduce (
354- function ( a , b ) {
355- return a . concat ( b ) ;
356- } ,
357- [ ]
358- ) ;
348+ . reduce ( function ( a , b ) {
349+ return a . concat ( b ) ;
350+ } , [ ] ) ;
359351 if ( timestamps . length !== this . speaker_labels . length ) {
360352 var msg ;
361353 if ( timestamps . length && ! this . speaker_labels . length ) {
362354 msg = 'No speaker_labels found. SpeakerStream requires speaker_labels to be enabled.' ;
363355 } else {
364- msg = 'Mismatch between number of word timestamps (' +
356+ msg =
357+ 'Mismatch between number of word timestamps (' +
365358 timestamps . length +
366359 ') and number of speaker_labels (' +
367360 this . speaker_labels . length +
0 commit comments