implementacao de interrupcao em audio streming

This commit is contained in:
2026-10-16 01:15:34 +00:00
parent 19a415daae
commit 2449b34137
12 changed files with 2119 additions and 85 deletions

83
tests/js/vad.test.mjs Normal file
View File

@@ -0,0 +1,83 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { VoiceActivityDetector } from "../../src/voice_assistant/audio_gateway/web/vad.js";
test("detects speech start after minimum duration", () => {
let starts = 0;
const vad = new VoiceActivityDetector({
minSpeechMs: 250,
onSpeechStart: () => starts++,
});
vad.start();
vad.process(0.04, 0);
vad.process(0.04, 100);
assert.equal(starts, 0);
vad.process(0.04, 260);
assert.equal(starts, 1);
});
test("detects speech end after silence", () => {
let ends = 0;
const vad = new VoiceActivityDetector({
minSpeechMs: 100,
silenceMs: 800,
onSpeechEnd: () => ends++,
});
vad.start();
vad.process(0.04, 0);
vad.process(0.04, 120);
vad.process(0.04, 300);
vad.process(0.001, 600);
vad.process(0.001, 1000);
assert.equal(ends, 0);
vad.process(0.001, 1101);
assert.equal(ends, 1);
});
test("ignores short noise spikes", () => {
let starts = 0;
const vad = new VoiceActivityDetector({
minSpeechMs: 250,
onSpeechStart: () => starts++,
});
vad.start();
vad.process(0.05, 0);
vad.process(0.001, 80);
vad.process(0.001, 300);
assert.equal(starts, 0);
});
test("stop disables detection", () => {
let starts = 0;
const vad = new VoiceActivityDetector({
minSpeechMs: 100,
onSpeechStart: () => starts++,
});
vad.start();
vad.stop();
vad.process(0.05, 0);
vad.process(0.05, 200);
assert.equal(starts, 0);
});