mirror of
https://github.com/bitbaum/speechkit.git
synced 2026-12-04 12:38:30 +01:00
Extracted from Heidi's speaking practice, where it measures Zurich German learners. Language-agnostic: vowels, fillers, dialect markers and the grammar code are passed in; nothing here names a language. Four layers: signal (pauses and runs from raw samples — works on a dialect nothing transcribes), evidence (a translated transcript is never evidence about form), words (rate, where a long pause fell, did the recogniser answer in the variety spoken), grammar (your own LanguageTool, filtered to what a speaker is answerable for). No pronunciation score, and a test on the built package fails if an export starts to look like one. dist/ committed so `github:bitbaum/speechkit#v1.0.0` installs without a build; CI fails if it drifts from the source. npm publishing is wired (tag-driven, tokenless) but gated off until the one-time passkey bootstrap in the README. 90 unit tests on the source, 4 on dist/. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
/**
|
|
* The BUILT package, as a consumer imports it.
|
|
*
|
|
* The unit tests in src/ run the TypeScript source directly. These run
|
|
* dist/index.js — what `github:bitbaum/speechkit` and npm actually deliver —
|
|
* so a broken rewrite of `./x.ts` to `./x.js`, or an export that exists in the
|
|
* source and not the entry point, fails here rather than in somebody's app.
|
|
*/
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import * as kit from "../dist/index.js";
|
|
|
|
test("the four layers are all reachable from the entry point", () => {
|
|
for (const name of [
|
|
"measureDelivery",
|
|
"usable",
|
|
"evidenceFrom",
|
|
"mayJudgeForm",
|
|
"measureSpoken",
|
|
"hesitations",
|
|
"markerVerdict",
|
|
"checkGrammar",
|
|
"fromLanguageTool",
|
|
]) {
|
|
assert.equal(typeof kit[name], "function", `${name} is not exported`);
|
|
}
|
|
assert.equal(kit.MIN_PAUSE_MS < kit.SEARCH_PAUSE_MS, true);
|
|
assert.equal(kit.SEARCH_PAUSE_MS < kit.STUCK_PAUSE_MS, true, "pause < searching < stuck");
|
|
});
|
|
|
|
test("THE REFUSAL IS PART OF THE API: nothing scores pronunciation", () => {
|
|
// Not an oversight to be filled in later. A score against a native ideal is a
|
|
// judgement about a person; see the README. If this fails, somebody added one.
|
|
const scorers = Object.keys(kit).filter((name) => /pronunc|accent|native|score/i.test(name));
|
|
assert.deepEqual(scorers, []);
|
|
});
|
|
|
|
test("a translated transcript is never evidence about form, from the built code", () => {
|
|
// The load-bearing rule, checked through the entry point rather than trusted.
|
|
const translating = { available: true, returnsSpokenVariety: false, wer: 0 };
|
|
assert.equal(kit.evidenceFrom(translating), "meaning-only");
|
|
assert.equal(kit.mayJudgeForm(translating), false);
|
|
});
|
|
|
|
test("the signal layer runs on raw samples with no language at all", () => {
|
|
const rate = 16000;
|
|
const samples = new Float32Array(rate * 3);
|
|
for (let i = 0; i < rate; i++) samples[i] = 0.3 * Math.sin((2 * Math.PI * 140 * i) / rate);
|
|
for (let i = rate * 2; i < rate * 3; i++)
|
|
samples[i] = 0.3 * Math.sin((2 * Math.PI * 140 * i) / rate);
|
|
const delivery = kit.measureDelivery(samples, rate);
|
|
assert.equal(delivery.pauseCount, 1, "one silence between two stretches of sound");
|
|
assert.equal(delivery.pauseSpans.length, 1);
|
|
});
|