repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/voice/__tests__/speech-output.test.ts
Rawimport { describe, expect, it } from "vitest";
import {
createSpeechOutputState,
selectSpeechModality,
stripMarkdownForSpeech,
} from "../src/speech-output.ts";
describe("speech output", () => {
it("waits for stable markdown lines and strips code fences without speaking code", () => {
const state = createSpeechOutputState();
expect(
stripMarkdownForSpeech("Hello **there**\n```ts\nsecret", state),
).toBe("Hello there");
expect(stripMarkdownForSpeech("\n```\nNext line", state, true)).toBe(
"Next line",
);
});
it("removes list markers and tables", () => {
const state = createSpeechOutputState();
expect(
stripMarkdownForSpeech(
"- First\n- Second\n| A | B |\n|---|---|\n",
state,
),
).toBe("First Second");
});
it("switches modality for long replies and inherently structured content", () => {
expect(
selectSpeechModality("One. Two. Three. Four. Five. Six. Seven.", 0),
).toBe("transcript");
expect(selectSpeechModality("A reply.", 40_001)).toBe("transcript");
expect(
selectSpeechModality("A reply.", 120_000, { maxPlaybackMs: 120_000 }),
).toBe("transcript");
expect(selectSpeechModality("```js\nrun()\n```", 0)).toBe("transcript");
expect(selectSpeechModality("Short reply.", 0)).toBe("speech");
expect(selectSpeechModality("a".repeat(4_001), 0)).toBe("transcript");
expect(selectSpeechModality("The function works in this class.", 0)).toBe(
"speech",
);
});
});