import { beforeAll, describe, expect, it } from "vitest";
import { initializeLogger } from "../log.js";
import { VAD } from "./vad.js";
beforeAll(() => {
  initializeLogger({ level: "silent", pretty: false });
});
const internals = (stream) => stream;
describe("inference.VAD updateOptions propagation", () => {
  it("fans out option changes to live streams", () => {
    const vad = new VAD({ minSilenceDuration: 250 });
    const stream = vad.stream();
    try {
      expect(internals(stream)._opts.minSilenceDuration).toBe(250);
      vad.updateOptions({ minSilenceDuration: 800 });
      expect(internals(stream)._opts.minSilenceDuration).toBe(800);
    } finally {
      stream.close();
    }
  });
  it("resizes a live stream speech buffer once the sample rate is known", () => {
    var _a;
    const sampleRate = 16e3;
    const vad = new VAD({ maxBufferedSpeech: 1e4, prefixPaddingDuration: 500 });
    const stream = vad.stream();
    try {
      const s = internals(stream);
      s._inputSampleRate = sampleRate;
      s._prefixPaddingSamples = Math.trunc(500 * sampleRate / 1e3);
      s._speechBuffer = new Int16Array(
        Math.trunc(1e4 * sampleRate / 1e3) + s._prefixPaddingSamples
      );
      vad.updateOptions({ maxBufferedSpeech: 2e4, prefixPaddingDuration: 1e3 });
      const expectedPrefix = Math.trunc(1e3 * sampleRate / 1e3);
      expect(s._prefixPaddingSamples).toBe(expectedPrefix);
      expect((_a = s._speechBuffer) == null ? void 0 : _a.length).toBe(
        Math.trunc(2e4 * sampleRate / 1e3) + expectedPrefix
      );
    } finally {
      stream.close();
    }
  });
});
//# sourceMappingURL=vad.test.js.map