+3
-2
@@ -25,6 +25,7 @@ export class VadSegmenter extends EventEmitter {
|
||||
push(frame) {
|
||||
const chunk = Buffer.from(frame || '');
|
||||
const rms = pcmRms(chunk);
|
||||
const durationMs = chunk.length / 2 / this.sampleRate * 1000;
|
||||
const voiced = rms >= this.params.threshold / 10; // PCM RMS is 0..1; QVAC threshold is posterior-like.
|
||||
this.emit('level', rms);
|
||||
if (!this.speaking && voiced) {
|
||||
@@ -33,8 +34,8 @@ export class VadSegmenter extends EventEmitter {
|
||||
}
|
||||
if (!this.speaking) return;
|
||||
this.buffer.push(chunk);
|
||||
if (voiced) { this.speechMs += this.frameMs; this.silenceMs = 0; }
|
||||
else { this.silenceMs += this.frameMs; }
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user