@@ -169,26 +169,23 @@ SpeakerStream.prototype.buildMessage = function() {
169
169
} ) ;
170
170
171
171
// 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
+ } , [ ] ) ;
192
189
193
190
// create new results
194
191
var results = utterances . map ( function ( utterance , i ) {
@@ -207,11 +204,12 @@ SpeakerStream.prototype.buildMessage = function() {
207
204
result . speaker = utterance . speaker ;
208
205
// overwrite the transcript and timestamps on the first alternative
209
206
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 ( ' ' ) + ' ' ;
215
213
alt . timestamps = utterance . timestamps ;
216
214
// overwrite the final value
217
215
result . final = final ;
@@ -266,12 +264,9 @@ SpeakerStream.prototype.handleResults = function(data) {
266
264
. filter ( function ( result ) {
267
265
return result . final ;
268
266
} )
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 ) ;
275
270
} ;
276
271
277
272
// sorts by start time and then end time
@@ -350,18 +345,16 @@ SpeakerStream.prototype._flush = function(done) {
350
345
. map ( function ( r ) {
351
346
return r . alternatives [ 0 ] . timestamps ;
352
347
} )
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
+ } , [ ] ) ;
359
351
if ( timestamps . length !== this . speaker_labels . length ) {
360
352
var msg ;
361
353
if ( timestamps . length && ! this . speaker_labels . length ) {
362
354
msg = 'No speaker_labels found. SpeakerStream requires speaker_labels to be enabled.' ;
363
355
} else {
364
- msg = 'Mismatch between number of word timestamps (' +
356
+ msg =
357
+ 'Mismatch between number of word timestamps (' +
365
358
timestamps . length +
366
359
') and number of speaker_labels (' +
367
360
this . speaker_labels . length +
0 commit comments