@@ -125,7 +125,6 @@ export class SpeechStream extends stt.SpeechStream {
125
125
constructor ( stt : STT , opts : STTOptions ) {
126
126
super ( stt ) ;
127
127
this . #opts = opts ;
128
- this . closed = false ;
129
128
this . #audioEnergyFilter = new AudioEnergyFilter ( ) ;
130
129
131
130
this . #run( ) ;
@@ -134,7 +133,7 @@ export class SpeechStream extends stt.SpeechStream {
134
133
async #run( maxRetry = 32 ) {
135
134
let retries = 0 ;
136
135
let ws : WebSocket ;
137
- while ( ! this . input . closed ) {
136
+ while ( ! this . inputClosed ) {
138
137
const streamURL = new URL ( API_BASE_URL_V1 ) ;
139
138
const params = {
140
139
model : this . #opts. model ,
@@ -193,7 +192,7 @@ export class SpeechStream extends stt.SpeechStream {
193
192
}
194
193
}
195
194
196
- this . closed = true ;
195
+ this . close ( ) ;
197
196
}
198
197
199
198
updateOptions ( opts : Partial < STTOptions > ) {
@@ -222,7 +221,10 @@ export class SpeechStream extends stt.SpeechStream {
222
221
samples100Ms ,
223
222
) ;
224
223
225
- for await ( const data of this . input ) {
224
+ while ( true ) {
225
+ const { done, value : data } = await this . inputReader . read ( ) ;
226
+ if ( done ) break ;
227
+
226
228
let frames : AudioFrame [ ] ;
227
229
if ( data === SpeechStream . FLUSH_SENTINEL ) {
228
230
frames = stream . flush ( ) ;
@@ -270,7 +272,7 @@ export class SpeechStream extends stt.SpeechStream {
270
272
// It's also possible we receive a transcript without a SpeechStarted event.
271
273
if ( this . #speaking) return ;
272
274
this . #speaking = true ;
273
- this . queue . put ( { type : stt . SpeechEventType . START_OF_SPEECH } ) ;
275
+ this . outputWriter . write ( { type : stt . SpeechEventType . START_OF_SPEECH } ) ;
274
276
break ;
275
277
}
276
278
// see this page:
@@ -288,16 +290,16 @@ export class SpeechStream extends stt.SpeechStream {
288
290
if ( alternatives [ 0 ] && alternatives [ 0 ] . text ) {
289
291
if ( ! this . #speaking) {
290
292
this . #speaking = true ;
291
- this . queue . put ( { type : stt . SpeechEventType . START_OF_SPEECH } ) ;
293
+ this . outputWriter . write ( { type : stt . SpeechEventType . START_OF_SPEECH } ) ;
292
294
}
293
295
294
296
if ( isFinal ) {
295
- this . queue . put ( {
297
+ this . outputWriter . write ( {
296
298
type : stt . SpeechEventType . FINAL_TRANSCRIPT ,
297
299
alternatives : [ alternatives [ 0 ] , ...alternatives . slice ( 1 ) ] ,
298
300
} ) ;
299
301
} else {
300
- this . queue . put ( {
302
+ this . outputWriter . write ( {
301
303
type : stt . SpeechEventType . INTERIM_TRANSCRIPT ,
302
304
alternatives : [ alternatives [ 0 ] , ...alternatives . slice ( 1 ) ] ,
303
305
} ) ;
@@ -309,7 +311,7 @@ export class SpeechStream extends stt.SpeechStream {
309
311
// a non-empty transcript (deepgram doesn't have a SpeechEnded event)
310
312
if ( isEndpoint && this . #speaking) {
311
313
this . #speaking = false ;
312
- this . queue . put ( { type : stt . SpeechEventType . END_OF_SPEECH } ) ;
314
+ this . outputWriter . write ( { type : stt . SpeechEventType . END_OF_SPEECH } ) ;
313
315
}
314
316
315
317
break ;
0 commit comments