Smooth Talk playback and gate audio tail
This commit is contained in:
+6
-2
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user