+5
-4
@@ -20,7 +20,7 @@ export class VadSegmenter extends EventEmitter {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
reset() { this.speaking = false; this.buffer = []; this.speechMs = 0; this.silenceMs = 0; }
|
||||
reset() { this.speaking = false; this.buffer = []; this.speechMs = 0; this.silenceMs = 0; this.recordingMs = 0; }
|
||||
|
||||
push(frame) {
|
||||
const chunk = Buffer.from(frame || '');
|
||||
@@ -34,11 +34,12 @@ export class VadSegmenter extends EventEmitter {
|
||||
}
|
||||
if (!this.speaking) return;
|
||||
this.buffer.push(chunk);
|
||||
this.recordingMs += durationMs;
|
||||
if (voiced) { this.speechMs += durationMs; this.silenceMs = 0; }
|
||||
else { this.silenceMs += durationMs; }
|
||||
if (this.speechMs >= this.params.maxSpeechDurationMs ||
|
||||
(this.speechMs >= this.params.minSpeechDurationMs && this.silenceMs >= this.params.minSilenceDurationMs)) {
|
||||
this.end();
|
||||
if (this.recordingMs >= this.params.maxSpeechDurationMs || this.silenceMs >= this.params.minSilenceDurationMs) {
|
||||
if (this.speechMs >= this.params.minSpeechDurationMs) this.end();
|
||||
else this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user