primeira versão customizada de VAD- Voice Activity Detection

This commit is contained in:
2026-10-30 19:15:01 +00:00
parent 2449b34137
commit aba05cb826
14 changed files with 3457 additions and 129 deletions

View File

@@ -82,8 +82,12 @@ export class PCMPlayer {
}
async enqueue(buffer) {
const generation = this.generation;
if (this.finished) {
throw new Error("Playback has already been finalized.");
// Playback was already stopped or finalized.
// Late audio chunks must not terminate the conversation.
return;
}
const samples = this.decodePCM(buffer);
@@ -94,8 +98,12 @@ export class PCMPlayer {
await this.context.resume();
if (generation !== this.generation) {
return;
}
if (this.finished) {
throw new Error("Playback was finalized during enqueue.");
return;
}
const audioBuffer = this.context.createBuffer(
@@ -116,9 +124,6 @@ export class PCMPlayer {
);
this.nextStartTime = startAt + audioBuffer.duration;
const generation = this.generation;
this.sources.add(source);
if (!this.playing) {