Files
ai-kit/test/speech.test.js
CatoandClaude Opus 5.5 ae0a311bc8 feat(speech): speechChain, speechConfigured and looksLikeSilence, defined once (1.20.0) (#81)
Heidi defined its Groq Whisper chain and its silence denylist in its own
lib; Loki has copies; Substrata had none, so its microphone had no server
leg. ai-kit owns the chains: this is the dictation one, beside freeChain,
with the guard against Whisper's silence artefacts ('Untertitelung des
ZDF', 'Amen.') typing words nobody said.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 04:55:54 -07:00

33 lines
1.1 KiB
JavaScript

/**
* The fleet's dictation chain and its silence guard, defined once.
*/
import { test } from "node:test";
import assert from "node:assert/strict";
import { looksLikeSilence, speechChain, speechConfigured } from "@bitbaum/ai-kit";
test("the speech chain is Whisper on Groq, turbo first, and claims no token pool", () => {
const chain = speechChain();
assert.deepEqual(
chain.map((l) => l.model),
["whisper-large-v3-turbo", "whisper-large-v3"],
);
assert.ok(chain.every((l) => l.provider.dailyTokens === 0));
});
test("configured only with the speech key", () => {
assert.equal(speechConfigured({}), false);
assert.equal(speechConfigured({ GROQ_API_KEY: " " }), false);
assert.equal(speechConfigured({ GROQ_API_KEY: "k" }), true);
});
test("Whisper's silence artefacts are recognised; real speech passes", () => {
for (const s of ["Untertitelung des ZDF, 2020", "Amen.", "Thank you.", "", " "])
assert.equal(looksLikeSilence(s), true, s);
for (const s of [
"Vielen Dank für Ihre Hilfe, können Sie mir sagen",
"What is the gallium price?",
])
assert.equal(looksLikeSilence(s), false, s);
});