File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
samples/js/live-audio-transcription-example Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -54,5 +54,5 @@ for await (const result of session.getTranscriptionStream()) {
5454 console .log (result .is_final ); // true for final results
5555}
5656
57- await client .stop ();
57+ await session .stop ();
5858```
Original file line number Diff line number Diff line change 9393 }
9494 } ) ;
9595
96+ let appendPending = false ;
9697 audioInput . on ( 'data' , ( buffer ) => {
98+ if ( appendPending ) return ; // drop frame while backpressured
9799 const pcm = new Uint8Array ( buffer ) ;
98- session . append ( pcm ) . catch ( ( err ) => {
100+ appendPending = true ;
101+ session . append ( pcm ) . then ( ( ) => {
102+ appendPending = false ;
103+ } ) . catch ( ( err ) => {
104+ appendPending = false ;
99105 console . error ( 'append error:' , err . message ) ;
100106 } ) ;
101107 } ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,10 @@ class AsyncQueue<T> {
6666 } ) ;
6767 }
6868
69+ if ( this . completed ) {
70+ throw new Error ( 'Cannot write to a completed queue.' ) ;
71+ }
72+
6973 this . queue . push ( item ) ;
7074 }
7175
@@ -290,6 +294,9 @@ export class LiveAudioTranscriptionSession {
290294 `Push failed (code=${ errorInfo ?. code ?? 'UNKNOWN' } ): ${ errorMsg } ` ,
291295 { cause : error }
292296 ) ;
297+ this . stopped = true ;
298+ this . started = false ;
299+ this . pushQueue ?. complete ( fatalError ) ;
293300 this . outputQueue ?. complete ( fatalError ) ;
294301 return ;
295302 }
@@ -388,8 +395,8 @@ export class LiveAudioTranscriptionSession {
388395 if ( this . started && ! this . stopped ) {
389396 await this . stop ( ) ;
390397 }
391- } catch ( error ) {
392- console . warn ( 'Error during dispose cleanup:' , error instanceof Error ? error . message : String ( error ) ) ;
398+ } catch {
399+ // Swallow errors during best-effort cleanup to keep dispose() silent.
393400 }
394401 }
395402}
You can’t perform that action at this time.
0 commit comments