primeira versão customizada de VAD- Voice Activity Detection
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user