@@ -115,20 +115,20 @@ class LanguageModel extends EventEmitter {
115
115
}
116
116
117
117
// on-token event
118
- this . emit ( 'token' , this . tokens [ this . tokens . length - 1 ] , this ) ;
118
+ this . emit ( 'token' , this ) ;
119
119
120
120
// redo word tokenization
121
121
const wordDelimiters = ' .,:;"“?!\n' ;
122
122
const re = new RegExp ( '(?=[' + wordDelimiters + '])|(?<=[' + wordDelimiters + '])' , 'g' ) ;
123
- const prevNumWords = this . words . length ;
124
- this . words = this . text . split ( re ) ;
123
+ const newWords = this . text . split ( re ) ;
125
124
// ignore the last word if we can't be certain it's complete
126
125
if ( ! wordDelimiters . includes ( this . text . slice ( - 1 ) ) && ! this . finished ) {
127
- this . words . pop ( ) ;
126
+ newWords . pop ( ) ;
128
127
}
129
- // on-word event
130
- for ( let i = prevNumWords ; i < this . words . length ; i ++ ) {
131
- this . emit ( 'word' , this . words [ i ] , this ) ;
128
+ // on-word events
129
+ for ( let i = this . words . length ; i < newWords . length ; i ++ ) {
130
+ this . words [ i ] = newWords [ i ] ;
131
+ this . emit ( 'word' , this ) ;
132
132
}
133
133
134
134
// on-finished promise/event/callback
@@ -137,9 +137,9 @@ class LanguageModel extends EventEmitter {
137
137
if ( this . promiseResolve ) {
138
138
this . promiseResolve ( this . text ) ;
139
139
}
140
- this . emit ( 'finish' , this . text , this ) ;
140
+ this . emit ( 'finish' , this ) ;
141
141
if ( this . callback ) {
142
- this . callback ( this . text , this ) ;
142
+ this . callback ( this ) ;
143
143
}
144
144
}
145
145
} , 'viifi' ) ;
0 commit comments