Smooth Talk playback and gate audio tail

This commit is contained in:
Mikei386
2026-09-03 23:19:51 +02:00
parent 65ce9642cc
commit 023c2ee40d
4 changed files with 22 additions and 10 deletions
+6 -2
View File
@@ -237,14 +237,18 @@ class AthenaTalkBridge {
const pcm = await this.synthesize(text, controller.signal);
if (generation !== this.generation || !this.isConnected())
return;
const frameBytes = 24000 * 2 / 10;
const frameBytes = 24000 * 2 / 50;
const playbackStartedAt = Date.now();
for (let offset = 0; offset < pcm.length; offset += frameBytes) {
if (controller.signal.aborted || generation !== this.generation || !this.isConnected()) {
return;
}
this.req.onAudio?.(pcm.subarray(offset, Math.min(offset + frameBytes, pcm.length)));
await new Promise((resolve) => setTimeout(resolve, 80));
await new Promise((resolve) => setTimeout(resolve, 18));
}
const audioDurationMs = pcm.length / (24000 * 2) * 1000;
const remainingPlaybackMs = Math.max(0, audioDurationMs - (Date.now() - playbackStartedAt));
await new Promise((resolve) => setTimeout(resolve, remainingPlaybackMs + 300));
this.req.onResponseDone?.({ status: "completed", responseId });
this.req.onEvent?.({ direction: "server", type: "response.done", responseId });
}