Skip to content

Commit a310d83

Browse files
committed
fix copilot
1 parent 1af8967 commit a310d83

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

samples/js/live-audio-transcription-example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
```

samples/js/live-audio-transcription-example/app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ try {
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
});

sdk/js/src/openai/liveAudioTranscriptionClient.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)