Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(test): make two platform-dependent tests pass off Windows, and clear lint

Etienne Lescot3c7dc904c54c
diff --git a/electron/native-bridge/services/compositorViewService.test.ts b/electron/native-bridge/services/compositorViewService.test.ts
index b0d7fee8b..4e2f5bbde 100644
--- a/electron/native-bridge/services/compositorViewService.test.ts
+++ b/electron/native-bridge/services/compositorViewService.test.ts
@@ -52,10 +52,15 @@ describe("ffmpegSharedBinCandidates", () => {
});
it("keeps an absolute pin absolute rather than nesting it under the crate dir", () => {
- writeCargoConfig(tmpRoot, `FFMPEG_DIR = "C:/vendor/ffmpeg"`);
+ // `path.isAbsolute` is platform-dependent — "C:/vendor" is absolute on
+ // Windows and relative on POSIX — so spell the pin through path.resolve
+ // and assert the behaviour rather than one platform's drive letter.
+ const absolutePin = path.resolve("/vendor/ffmpeg").replace(/\\/g, "/");
+ writeCargoConfig(tmpRoot, `FFMPEG_DIR = "${absolutePin}"`);
const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));
- expect(candidates[0]).toBe("C:/vendor/ffmpeg/bin");
+ expect(candidates[0]).toBe(`${absolutePin}/bin`);
+ expect(candidates[0]).not.toContain("poc-d3d");
});
it("starts at the arch-tagged native bin dir when there is no cargo pin to read", () => {
diff --git a/electron/stt/whisperServer.test.ts b/electron/stt/whisperServer.test.ts
index 70558af4c..35d789586 100644
--- a/electron/stt/whisperServer.test.ts
+++ b/electron/stt/whisperServer.test.ts
@@ -229,7 +229,9 @@ describe("WhisperServerManager", () => {
dir,
process.platform === "win32" ? "whisper-stt-server.exe" : "whisper-stt-server",
);
- await fs.writeFile(fakeBinaryPath, "x");
+ // mode 0o755: the manager refuses a helper it cannot execute, and the
+ // default write mode is not executable on POSIX.
+ await fs.writeFile(fakeBinaryPath, "x", { mode: 0o755 });
const fakeChild = {
stdout: { on: vi.fn() },
stderr: { on: vi.fn() },
@@ -273,7 +275,9 @@ describe("WhisperServerManager", () => {
dir,
process.platform === "win32" ? "whisper-stt-server.exe" : "whisper-stt-server",
);
- await fs.writeFile(fakeBinaryPath, "x");
+ // Executable on purpose: this test asserts the *model* check fires, so
+ // the binary must get past the executability check first.
+ await fs.writeFile(fakeBinaryPath, "x", { mode: 0o755 });
const mgr = new WhisperServerManager();
await expect(
mgr.start({
diff --git a/scripts/build-windows-compositor-addon.mjs b/scripts/build-windows-compositor-addon.mjs
index 876e9cacf..8bea0e874 100644
--- a/scripts/build-windows-compositor-addon.mjs
+++ b/scripts/build-windows-compositor-addon.mjs
@@ -56,7 +56,13 @@ function findVcVarsAll() {
}
if (process.env.VSINSTALLDIR) {
- const candidate = path.join(process.env.VSINSTALLDIR, "VC", "Auxiliary", "Build", "vcvarsall.bat");
+ const candidate = path.join(
+ process.env.VSINSTALLDIR,
+ "VC",
+ "Auxiliary",
+ "Build",
+ "vcvarsall.bat",
+ );
if (fs.existsSync(candidate)) {
return candidate;
}
@@ -91,7 +97,14 @@ function findVcVarsAll() {
return direct;
}
for (const edition of editions) {
- const nested = path.join(channelDir, edition, "VC", "Auxiliary", "Build", "vcvarsall.bat");
+ const nested = path.join(
+ channelDir,
+ edition,
+ "VC",
+ "Auxiliary",
+ "Build",
+ "vcvarsall.bat",
+ );
if (fs.existsSync(nested)) {
return nested;
}
@@ -141,9 +154,14 @@ async function runInVsEnv(command) {
);
fs.writeFileSync(
cmdPath,
- ["@echo off", `call "${vcvarsAll}" x64`, "if errorlevel 1 exit /b %errorlevel%", command, "exit /b %errorlevel%", ""].join(
- "\r\n",
- ),
+ [
+ "@echo off",
+ `call "${vcvarsAll}" x64`,
+ "if errorlevel 1 exit /b %errorlevel%",
+ command,
+ "exit /b %errorlevel%",
+ "",
+ ].join("\r\n"),
);
try {
await run("cmd.exe", ["/d", "/c", cmdPath], { cwd: POC_D3D_DIR });
diff --git a/scripts/build-windows-wgc-helper.mjs b/scripts/build-windows-wgc-helper.mjs
index 10566a657..60384efa3 100644
--- a/scripts/build-windows-wgc-helper.mjs
+++ b/scripts/build-windows-wgc-helper.mjs
@@ -43,7 +43,13 @@ function findVcVarsAll() {
}
if (process.env.VSINSTALLDIR) {
- const candidate = path.join(process.env.VSINSTALLDIR, "VC", "Auxiliary", "Build", "vcvarsall.bat");
+ const candidate = path.join(
+ process.env.VSINSTALLDIR,
+ "VC",
+ "Auxiliary",
+ "Build",
+ "vcvarsall.bat",
+ );
if (fs.existsSync(candidate)) {
return candidate;
}
@@ -82,7 +88,14 @@ function findVcVarsAll() {
return direct;
}
for (const edition of editions) {
- const nested = path.join(channelDir, edition, "VC", "Auxiliary", "Build", "vcvarsall.bat");
+ const nested = path.join(
+ channelDir,
+ edition,
+ "VC",
+ "Auxiliary",
+ "Build",
+ "vcvarsall.bat",
+ );
if (fs.existsSync(nested)) {
return nested;
}
diff --git a/scripts/check-docs.mjs b/scripts/check-docs.mjs
index 386930b91..c15497c12 100644
--- a/scripts/check-docs.mjs
+++ b/scripts/check-docs.mjs
@@ -113,7 +113,9 @@ for (const file of files) {
}
// No stale `docs/` path prefix.
- for (const [match] of text.matchAll(/(?<![\w/-])docs\/(?:architecture|engineering|testing|tests)\//g)) {
+ for (const [match] of text.matchAll(
+ /(?<![\w/-])docs\/(?:architecture|engineering|testing|tests)\//g,
+ )) {
errors.push(`${rel}: stale path prefix "${match}" (tree is technical-documentation/)`);
}
diff --git a/scripts/e2e-pipeline-smoke.mjs b/scripts/e2e-pipeline-smoke.mjs
index d3695dc01..fc9a1afc6 100644
--- a/scripts/e2e-pipeline-smoke.mjs
+++ b/scripts/e2e-pipeline-smoke.mjs
@@ -39,9 +39,9 @@ const MODEL_PATH = join(
// Lazy import — only the type module + the bits we need. The main thing
// we want to verify is that our Electron modules wire up correctly.
-const transcriptionContract = await import("../electron/stt/transcriptionContract.ts").catch(
- () => null,
-);
+// The binding is deliberately dropped: the import is attempted for its own
+// sake and the module's value is never read.
+await import("../electron/stt/transcriptionContract.ts").catch(() => null);
// The .ts file isn't loadable directly via plain Node — that's fine, we
// only need to confirm the actual server pipeline behaves correctly when
// invoked the same way the IPC handler does.
diff --git a/scripts/fetch-ffmpeg.mjs b/scripts/fetch-ffmpeg.mjs
index 8fa81c34a..0584d03bf 100644
--- a/scripts/fetch-ffmpeg.mjs
+++ b/scripts/fetch-ffmpeg.mjs
@@ -287,7 +287,12 @@ async function fetchSharedDlls(tag, binDir) {
// --force same as the static exe, checked once we know what we'd extract.
const alreadyVendored = fs
.readdirSync(binDir, { withFileTypes: true })
- .some((e) => e.isFile() && e.name.toLowerCase().endsWith(".dll") && e.name.toLowerCase().startsWith("av"));
+ .some(
+ (e) =>
+ e.isFile() &&
+ e.name.toLowerCase().endsWith(".dll") &&
+ e.name.toLowerCase().startsWith("av"),
+ );
if (alreadyVendored && !process.argv.includes("--force")) {
console.log(`\nShared ffmpeg DLLs already present in ${binDir}. Use --force to re-vendor.`);
return;
@@ -297,7 +302,8 @@ async function fetchSharedDlls(tag, binDir) {
const tmp = await downloadAndExtract(spec);
try {
const exe = findExe(tmp, "ffmpeg.exe");
- if (!exe) throw new Error(`ffmpeg.exe not found inside ${spec.asset} (needed to verify licence)`);
+ if (!exe)
+ throw new Error(`ffmpeg.exe not found inside ${spec.asset} (needed to verify licence)`);
// Same source commit as the static build, but configure flags are a
// separate BtbN job — verify this artifact's licence independently
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/analyze.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/analyze.mjs
index 91b9509af..9115be1e9 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/analyze.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/analyze.mjs
@@ -9,41 +9,42 @@ const dur = parseFloat(durationSec);
let text = "";
let words = [];
for (const seg of d.segments || []) {
- text += seg.text;
- for (const w of seg.words || []) words.push(w);
+ text += seg.text;
+ for (const w of seg.words || []) words.push(w);
}
let monotonic = true;
let maxBacktrack = 0;
let coverageGaps = [];
for (let i = 1; i < words.length; i++) {
- if (words[i].start < words[i - 1].start) {
- monotonic = false;
- maxBacktrack = Math.max(maxBacktrack, words[i - 1].start - words[i].start);
- }
- if (words[i].end < words[i].start) {
- coverageGaps.push(`word[${i}] '${words[i].word}' end<start`);
- }
+ if (words[i].start < words[i - 1].start) {
+ monotonic = false;
+ maxBacktrack = Math.max(maxBacktrack, words[i - 1].start - words[i].start);
+ }
+ if (words[i].end < words[i].start) {
+ coverageGaps.push(`word[${i}] '${words[i].word}' end<start`);
+ }
}
const lastWordEnd = words.length ? words[words.length - 1].end : 0;
const zeroStartCount = words.filter((w, i) => i > 0 && w.start === 0).length;
console.log(
- JSON.stringify(
- {
- detected_language: d.detected_language,
- numSegments: (d.segments || []).length,
- numWords: words.length,
- text: text.trim(),
- monotonic,
- maxBacktrack,
- lastWordEnd,
- clipDuration: dur,
- zeroStartCountExcludingFirst: zeroStartCount,
- segmentsWithoutWords: (d.segments || []).filter((s) => !s.words || s.words.length === 0).length,
- },
- null,
- 2
- )
+ JSON.stringify(
+ {
+ detected_language: d.detected_language,
+ numSegments: (d.segments || []).length,
+ numWords: words.length,
+ text: text.trim(),
+ monotonic,
+ maxBacktrack,
+ lastWordEnd,
+ clipDuration: dur,
+ zeroStartCountExcludingFirst: zeroStartCount,
+ segmentsWithoutWords: (d.segments || []).filter((s) => !s.words || s.words.length === 0)
+ .length,
+ },
+ null,
+ 2,
+ ),
);
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/debug_jfk.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/debug_jfk.mjs
index 64f275ad2..be88b80b8 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/debug_jfk.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/debug_jfk.mjs
@@ -1,7 +1,12 @@
// debug_jfk.mjs — Compare wcpp-cpu-fp16 vs ct2-fp16 word-by-word for jfk.wav
import { promises as fs } from "node:fs";
-const a = JSON.parse(await fs.readFile("tools/stt-eval/whispercpp-dtw-poc/results/wcpp_cpu_fp16_jfk.json", "utf8"));
-const b = JSON.parse(await fs.readFile("tools/stt-eval/whispercpp-dtw-poc/results/ct2_fp16_jfk.json", "utf8"));
+
+const a = JSON.parse(
+ await fs.readFile("tools/stt-eval/whispercpp-dtw-poc/results/wcpp_cpu_fp16_jfk.json", "utf8"),
+);
+const b = JSON.parse(
+ await fs.readFile("tools/stt-eval/whispercpp-dtw-poc/results/ct2_fp16_jfk.json", "utf8"),
+);
const wa = a.segments[0].words;
const wb = b.segments[0].words;
console.log("wcpp words:", wa.length, "ct2 words:", wb.length);
@@ -9,14 +14,15 @@ const maxN = Math.max(wa.length, wb.length);
for (let i = 0; i < maxN; i++) {
const aw = wa[i] || { word: "<eof>", start: 0, end: 0 };
const bw = wb[i] || { word: "<eof>", start: 0, end: 0 };
- const dw = aw.end - aw.start, dc = bw.end - bw.start;
+ const dw = aw.end - aw.start,
+ dc = bw.end - bw.start;
const dStart = Math.abs(aw.start - bw.start) * 1000;
- const dEnd = Math.abs(aw.end - bw.end) * 1000;
+ const dEnd = Math.abs(aw.end - bw.end) * 1000;
console.log(
` ${String(i).padStart(2)} ` +
- `wcpp=${aw.word.padEnd(15)}[${aw.start.toFixed(2)},${aw.end.toFixed(2)}] ` +
- `ct2 =${bw.word.padEnd(15)}[${bw.start.toFixed(2)},${bw.end.toFixed(2)}] ` +
- `Δs=${dStart.toFixed(0).padStart(5)}ms Δe=${dEnd.toFixed(0).padStart(5)}ms ` +
- `wcpp_dur=${(dw*1000).toFixed(0).padStart(5)}ms ct2_dur=${(dc*1000).toFixed(0).padStart(5)}ms`,
+ `wcpp=${aw.word.padEnd(15)}[${aw.start.toFixed(2)},${aw.end.toFixed(2)}] ` +
+ `ct2 =${bw.word.padEnd(15)}[${bw.start.toFixed(2)},${bw.end.toFixed(2)}] ` +
+ `Δs=${dStart.toFixed(0).padStart(5)}ms Δe=${dEnd.toFixed(0).padStart(5)}ms ` +
+ `wcpp_dur=${(dw * 1000).toFixed(0).padStart(5)}ms ct2_dur=${(dc * 1000).toFixed(0).padStart(5)}ms`,
);
}
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/extract_text.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/extract_text.mjs
index e1ca37b3f..c4f62ec10 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/extract_text.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/extract_text.mjs
@@ -1,4 +1,5 @@
import fs from "fs";
+
const [, , jsonPath] = process.argv;
const d = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
process.stdout.write((d.segments || []).map((s) => s.text).join(""));
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/run_ct2.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/run_ct2.mjs
index 9277903e5..fd5f37dd9 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/run_ct2.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/run_ct2.mjs
@@ -14,15 +14,7 @@ import http from "node:http";
import path from "node:path";
import process from "node:process";
-const [
- ,
- ,
- resultsDir,
- modeArg,
- portArg,
- modelDir,
- ...fixtures
-] = process.argv;
+const [, , resultsDir, modeArg, portArg, modelDir, ...fixtures] = process.argv;
if (!resultsDir || !modeArg || !portArg || !modelDir || fixtures.length === 0) {
process.stderr.write(
"usage: node run_ct2.mjs <results-dir> <int8|fp16> <port> <model-dir> <fixture.wav> [...]\n",
@@ -38,14 +30,7 @@ const port = Number.parseInt(portArg, 10);
const serverExe =
"C:/Users/camil/Documents/repos/openscreen-new/electron/native/bin/win32-x64/ctranslate2-server-ctranslate2-cpu.exe";
-const args = [
- "--model",
- modelDir,
- "--port",
- String(port),
- "--host",
- "127.0.0.1",
-];
+const args = ["--model", modelDir, "--port", String(port), "--host", "127.0.0.1"];
if (mode === "int8") args.push("--int8");
await fs.mkdir(resultsDir, { recursive: true });
@@ -147,9 +132,7 @@ for (const fixture of fixtures) {
const outPath = path.join(resultsDir, `ct2_${mode}_${name}.json`);
await fs.writeFile(outPath, body);
- timingsLines.push(
- `${name}\t${audio_s.toFixed(4)}\t${wall_s.toFixed(4)}\t${rtf.toFixed(4)}`,
- );
+ timingsLines.push(`${name}\t${audio_s.toFixed(4)}\t${wall_s.toFixed(4)}\t${rtf.toFixed(4)}`);
process.stdout.write(
`ct2 ${mode} ${name}: wall=${wall_s.toFixed(3)}s audio=${audio_s.toFixed(3)}s rtf=${rtf.toFixed(3)}\n`,
);
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/run_wcpp.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/run_wcpp.mjs
index baa6d98b4..8c5f31b38 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/run_wcpp.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/run_wcpp.mjs
@@ -11,15 +11,7 @@ import { promises as fs } from "node:fs";
import path from "node:path";
import process from "node:process";
-const [
- ,
- ,
- resultsDir,
- backend,
- modelPath,
- benchExe,
- ...fixtures
-] = process.argv;
+const [, , resultsDir, backend, modelPath, benchExe, ...fixtures] = process.argv;
if (!resultsDir || !backend || !modelPath || !benchExe || fixtures.length === 0) {
process.stderr.write(
"usage: node run_wcpp.mjs <results-dir> <backend> <model.bin> <bench-exe> <fixture.wav> [...]\n",
@@ -46,10 +38,11 @@ for (const fixture of fixtures) {
});
const stderr = r.stderr.toString("utf8");
const stdout = r.stdout;
- const guardrailLine = stderr
- .split(/\r?\n/)
- .reverse()
- .find((l) => l.includes("§4.1 guardrail")) || "(no guardrail line in stderr)";
+ const guardrailLine =
+ stderr
+ .split(/\r?\n/)
+ .reverse()
+ .find((l) => l.includes("§4.1 guardrail")) || "(no guardrail line in stderr)";
if (r.status !== 0) {
process.stderr.write(`FAIL ${name}: exit ${r.status} — ${guardrailLine}\n${stderr}`);
continue;
@@ -57,14 +50,12 @@ for (const fixture of fixtures) {
const jsonPath = path.join(resultsDir, `wcpp_${backend}_${precTag}_${name}.json`);
await fs.writeFile(jsonPath, stdout);
- const elapsed_s = r.signal ? NaN : (process.hrtime.bigint?.() ?? 0); // fallback
- // We trust the harness's own elapsed_s — read it from JSON.
+ // We trust the harness's own elapsed_s — read it from JSON. `rtf` below is
+ // recomputed from it rather than taken from the report.
let wall_s = NaN;
- let reported_rtf = NaN;
try {
const parsed = JSON.parse(stdout.toString("utf8"));
- wall_s = parsed.timing?.elapsed_s ?? NaN;
- reported_rtf = parsed.timing?.rtf ?? NaN;
+ wall_s = parsed.timing?.elapsed_s ?? NaN;
} catch (e) {
process.stderr.write(`WARN ${name}: JSON parse failed: ${e.message}\n`);
}
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/score_all.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/score_all.mjs
index 30b623c5e..970661ef2 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/score_all.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/score_all.mjs
@@ -8,8 +8,8 @@
// - results/wer_table.tsv
// - results/timestamp_headtohead.json (median/p90, gross disagreements)
-import { promises as fs } from "node:fs";
import { spawnSync } from "node:child_process";
+import { promises as fs } from "node:fs";
import path from "node:path";
import process from "node:process";
@@ -17,7 +17,6 @@ const ROOT = process.cwd();
const POC = path.join(ROOT, "tools", "stt-eval", "whispercpp-dtw-poc");
const RESULTS = path.join(POC, "results");
const REFS = path.join(POC, "fixtures", "refs");
-const FIXTURES = path.join(POC, "fixtures");
const HARNESS = path.join(POC, "harness");
const audioDur = {
@@ -25,8 +24,8 @@ const audioDur = {
librispeech_demo_0: 5.851,
librispeech_demo_1: 4.438,
librispeech_demo_2: 11.967,
- librispeech_demo_3: 9.500,
- librispeech_demo_4: 29.130,
+ librispeech_demo_3: 9.5,
+ librispeech_demo_4: 29.13,
"two-min-clip": 130.324,
};
@@ -62,8 +61,6 @@ function flattenWords(json) {
// Per-fixture WER + analyze.
const runs = []; // { run, fixture, jsonPath, refPath, audio_s, hyp, ref, edits, refWords, wer, monotonic, maxBacktrack, lastWordEnd, numWords, numSegments, segmentsWithoutWords, zeroStartCountExcludingFirst }
-const fixtures = Object.keys(audioDur);
-
// Read the CT2 timings directly from the timings_*.tsv files, since the
// CT2 server's JSON response has no `timing` field.
async function readTimingsTsv(name) {
@@ -77,12 +74,12 @@ async function readTimingsTsv(name) {
}
return out;
}
-const ct2Timings = await readTimingsTsv("timings_int8.tsv");
-const ct2Fp16Timings = await readTimingsTsv("timings_fp16.tsv");
-const wcppCpuFp16 = await readTimingsTsv("timings_wcpp_cpu_fp16.tsv");
-const wcppCpuQ80 = await readTimingsTsv("timings_wcpp_cpu_q8_0.tsv");
-const wcppVulkanFp16 = await readTimingsTsv("timings_wcpp_vulkan_fp16.tsv");
-const wcppVulkanQ80 = await readTimingsTsv("timings_wcpp_vulkan_q8_0.tsv");
+const ct2Timings = await readTimingsTsv("timings_int8.tsv");
+const ct2Fp16Timings = await readTimingsTsv("timings_fp16.tsv");
+const wcppCpuFp16 = await readTimingsTsv("timings_wcpp_cpu_fp16.tsv");
+const wcppCpuQ80 = await readTimingsTsv("timings_wcpp_cpu_q8_0.tsv");
+const wcppVulkanFp16 = await readTimingsTsv("timings_wcpp_vulkan_fp16.tsv");
+const wcppVulkanQ80 = await readTimingsTsv("timings_wcpp_vulkan_q8_0.tsv");
const jsonFiles = (await fs.readdir(RESULTS))
.filter((f) => f.endsWith(".json") && !f.endsWith("error.json"))
@@ -93,14 +90,14 @@ for (const jf of jsonFiles) {
const mWc = jf.match(/^(wcpp)_(cpu|vulkan|cuda)_(fp16|q8_0)_(.+)\.json$/);
let engine, kind, prec, fixture;
if (mCt) {
- engine = mCt[1];
- kind = mCt[2];
- prec = mCt[2];
+ engine = mCt[1];
+ kind = mCt[2];
+ prec = mCt[2];
fixture = mCt[3];
} else if (mWc) {
- engine = mWc[1];
- kind = mWc[2];
- prec = mWc[3];
+ engine = mWc[1];
+ kind = mWc[2];
+ prec = mWc[3];
fixture = mWc[4];
} else {
continue;
@@ -117,10 +114,16 @@ for (const jf of jsonFiles) {
// a re-derivation of the WAV header.
let timing = { audio_s: undefined, wall_s: undefined, rtf: undefined };
if (engine === "wcpp") {
- const t = (kind === "cpu" && prec === "fp16") ? wcppCpuFp16 :
- (kind === "cpu" && prec === "q8_0") ? wcppCpuQ80 :
- (kind === "vulkan" && prec === "fp16") ? wcppVulkanFp16 :
- (kind === "vulkan" && prec === "q8_0") ? wcppVulkanQ80 : {};
+ const t =
+ kind === "cpu" && prec === "fp16"
+ ? wcppCpuFp16
+ : kind === "cpu" && prec === "q8_0"
+ ? wcppCpuQ80
+ : kind === "vulkan" && prec === "fp16"
+ ? wcppVulkanFp16
+ : kind === "vulkan" && prec === "q8_0"
+ ? wcppVulkanQ80
+ : {};
if (t[fixture]) timing = t[fixture];
} else if (engine === "ct2") {
const t = prec === "int8" ? ct2Timings : ct2Fp16Timings;
@@ -144,9 +147,8 @@ for (const jf of jsonFiles) {
...json,
segments: (json.segments || []).map((seg) => ({
...seg,
- words: (seg.words || []).filter((w) =>
- Number.isFinite(w.start) && Number.isFinite(w.end) &&
- w.start < 1e6 && w.end < 1e6,
+ words: (seg.words || []).filter(
+ (w) => Number.isFinite(w.start) && Number.isFinite(w.end) && w.start < 1e6 && w.end < 1e6,
),
})),
};
@@ -180,21 +182,47 @@ for (const jf of jsonFiles) {
// WER table (TSV).
const werHeader = [
- "run", "engine", "backend", "prec", "fixture",
- "audio_s", "rtf", "refWords", "edits", "wer",
- "numWords", "numSegments", "monotonic", "maxBacktrack",
- "lastWordEnd", "zeroStartCount", "segmentsWithoutWords",
+ "run",
+ "engine",
+ "backend",
+ "prec",
+ "fixture",
+ "audio_s",
+ "rtf",
+ "refWords",
+ "edits",
+ "wer",
+ "numWords",
+ "numSegments",
+ "monotonic",
+ "maxBacktrack",
+ "lastWordEnd",
+ "zeroStartCount",
+ "segmentsWithoutWords",
];
const werLines = [werHeader.join("\t")];
for (const r of runs) {
- werLines.push([
- r.run, r.engine, r.kind, r.prec, r.fixture,
- r.audio_s?.toFixed?.(4) ?? "",
- r.rtf?.toFixed?.(4) ?? "",
- r.refWords, r.edits, r.wer?.toFixed?.(4) ?? "",
- r.numWords, r.numSegments, r.monotonic, r.maxBacktrack?.toFixed?.(3),
- r.lastWordEnd?.toFixed?.(3), r.zeroStartCount, r.segmentsWithoutWords,
- ].join("\t"));
+ werLines.push(
+ [
+ r.run,
+ r.engine,
+ r.kind,
+ r.prec,
+ r.fixture,
+ r.audio_s?.toFixed?.(4) ?? "",
+ r.rtf?.toFixed?.(4) ?? "",
+ r.refWords,
+ r.edits,
+ r.wer?.toFixed?.(4) ?? "",
+ r.numWords,
+ r.numSegments,
+ r.monotonic,
+ r.maxBacktrack?.toFixed?.(3),
+ r.lastWordEnd?.toFixed?.(3),
+ r.zeroStartCount,
+ r.segmentsWithoutWords,
+ ].join("\t"),
+ );
}
await fs.writeFile(path.join(RESULTS, "wer_table.tsv"), werLines.join("\n") + "\n", "utf8");
process.stdout.write(`wrote ${path.join(RESULTS, "wer_table.tsv")} (${runs.length} rows)\n`);
@@ -223,29 +251,47 @@ async function alignHeadToHead(precA, precB) {
byFixture.set(r.fixture, e);
}
}
- const dStart = [], dEnd = [], dWcppStartToCt2End = [], dWcppMidToCt2Mid = [];
+ const dStart = [],
+ dEnd = [],
+ dWcppStartToCt2End = [],
+ dWcppMidToCt2Mid = [];
const gross = [];
for (const [fixture, { a, b }] of byFixture.entries()) {
if (!a || !b) continue;
const jsonA = JSON.parse(await fs.readFile(path.join(RESULTS, `${a.run}.json`), "utf8"));
const jsonB = JSON.parse(await fs.readFile(path.join(RESULTS, `${b.run}.json`), "utf8"));
- const wordsA = flattenWords(jsonA).map((w) => ({ ...w, _key: normalizeWord(w.word) })).filter((w) => w._key);
- const wordsB = flattenWords(jsonB).map((w) => ({ ...w, _key: normalizeWord(w.word) })).filter((w) => w._key);
- let i = 0, j = 0;
+ const wordsA = flattenWords(jsonA)
+ .map((w) => ({ ...w, _key: normalizeWord(w.word) }))
+ .filter((w) => w._key);
+ const wordsB = flattenWords(jsonB)
+ .map((w) => ({ ...w, _key: normalizeWord(w.word) }))
+ .filter((w) => w._key);
+ let i = 0,
+ j = 0;
while (i < wordsA.length && j < wordsB.length) {
if (wordsA[i]._key === wordsB[j]._key) {
const ds = Math.abs(wordsA[i].start - wordsB[j].start) * 1000;
- const de = Math.abs(wordsA[i].end - wordsB[j].end) * 1000;
- const dwx = Math.abs(wordsA[i].start - wordsB[j].end) * 1000;
- const dmid = Math.abs((wordsA[i].start + wordsA[i].end)/2 - (wordsB[j].start + wordsB[j].end)/2) * 1000;
+ const de = Math.abs(wordsA[i].end - wordsB[j].end) * 1000;
+ const dwx = Math.abs(wordsA[i].start - wordsB[j].end) * 1000;
+ const dmid =
+ Math.abs((wordsA[i].start + wordsA[i].end) / 2 - (wordsB[j].start + wordsB[j].end) / 2) *
+ 1000;
dStart.push(ds);
dEnd.push(de);
dWcppStartToCt2End.push(dwx);
dWcppMidToCt2Mid.push(dmid);
if (ds > 200 || de > 200) {
- gross.push({ fixture, word: wordsA[i]._key, wcpp: { s: wordsA[i].start, e: wordsA[i].end }, ct2: { s: wordsB[j].start, e: wordsB[j].end }, ds, de });
+ gross.push({
+ fixture,
+ word: wordsA[i]._key,
+ wcpp: { s: wordsA[i].start, e: wordsA[i].end },
+ ct2: { s: wordsB[j].start, e: wordsB[j].end },
+ ds,
+ de,
+ });
}
- i++; j++;
+ i++;
+ j++;
} else {
i++;
}
@@ -260,22 +306,22 @@ async function alignHeadToHead(precA, precB) {
return {
count: dStart.length,
dStart_median_ms: pct(dStart, 0.5),
- dStart_p90_ms: pct(dStart, 0.9),
- dStart_max_ms: Math.max(...dStart, 0),
- dEnd_median_ms: pct(dEnd, 0.5),
- dEnd_p90_ms: pct(dEnd, 0.9),
- dEnd_max_ms: Math.max(...dEnd, 0),
+ dStart_p90_ms: pct(dStart, 0.9),
+ dStart_max_ms: Math.max(...dStart, 0),
+ dEnd_median_ms: pct(dEnd, 0.5),
+ dEnd_p90_ms: pct(dEnd, 0.9),
+ dEnd_max_ms: Math.max(...dEnd, 0),
dWcppStartToCt2End_median_ms: pct(dWcppStartToCt2End, 0.5),
- dWcppStartToCt2End_p90_ms: pct(dWcppStartToCt2End, 0.9),
- dWcppMidToCt2Mid_median_ms: pct(dWcppMidToCt2Mid, 0.5),
- dWcppMidToCt2Mid_p90_ms: pct(dWcppMidToCt2Mid, 0.9),
- gross_count: gross.length,
- gross_examples: gross.slice(0, 20),
+ dWcppStartToCt2End_p90_ms: pct(dWcppStartToCt2End, 0.9),
+ dWcppMidToCt2Mid_median_ms: pct(dWcppMidToCt2Mid, 0.5),
+ dWcppMidToCt2Mid_p90_ms: pct(dWcppMidToCt2Mid, 0.9),
+ gross_count: gross.length,
+ gross_examples: gross.slice(0, 20),
};
}
-const h_fp16_vs_fp16 = await alignHeadToHead("fp16", "fp16");
-const h_q8_0_vs_int8 = await alignHeadToHead("q8_0", "int8");
+const h_fp16_vs_fp16 = await alignHeadToHead("fp16", "fp16");
+const h_q8_0_vs_int8 = await alignHeadToHead("q8_0", "int8");
const headToHead = {
"fp16-vs-fp16 (wcpp_cpu_fp16 vs ct2_fp16)": h_fp16_vs_fp16,
@@ -299,10 +345,10 @@ process.stdout.write("\n=== §5.1 Word-timestamp head-to-head (4 metrics) ===\n"
for (const [k, v] of Object.entries(headToHead)) {
process.stdout.write(
`${k} (n=${v.count}):\n` +
- ` Δstart (wcpp.start vs ct2.start): median=${v.dStart_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dStart_p90_ms?.toFixed(0).padStart(5)}ms max=${v.dStart_max_ms?.toFixed(0).padStart(6)}ms\n` +
- ` Δend (wcpp.end vs ct2.end): median=${v.dEnd_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dEnd_p90_ms?.toFixed(0).padStart(5)}ms max=${v.dEnd_max_ms?.toFixed(0).padStart(6)}ms\n` +
- ` ΔwcppStart↔ct2End (t_dtw ≈ word-end?): median=${v.dWcppStartToCt2End_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dWcppStartToCt2End_p90_ms?.toFixed(0).padStart(5)}ms\n` +
- ` Δmid (wcpp.mid vs ct2.mid): median=${v.dWcppMidToCt2Mid_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dWcppMidToCt2Mid_p90_ms?.toFixed(0).padStart(5)}ms\n` +
- ` gross(>200ms any): ${v.gross_count}\n`,
+ ` Δstart (wcpp.start vs ct2.start): median=${v.dStart_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dStart_p90_ms?.toFixed(0).padStart(5)}ms max=${v.dStart_max_ms?.toFixed(0).padStart(6)}ms\n` +
+ ` Δend (wcpp.end vs ct2.end): median=${v.dEnd_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dEnd_p90_ms?.toFixed(0).padStart(5)}ms max=${v.dEnd_max_ms?.toFixed(0).padStart(6)}ms\n` +
+ ` ΔwcppStart↔ct2End (t_dtw ≈ word-end?): median=${v.dWcppStartToCt2End_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dWcppStartToCt2End_p90_ms?.toFixed(0).padStart(5)}ms\n` +
+ ` Δmid (wcpp.mid vs ct2.mid): median=${v.dWcppMidToCt2Mid_median_ms?.toFixed(0).padStart(5)}ms p90=${v.dWcppMidToCt2Mid_p90_ms?.toFixed(0).padStart(5)}ms\n` +
+ ` gross(>200ms any): ${v.gross_count}\n`,
);
}
diff --git a/tools/stt-eval/whispercpp-dtw-poc/harness/wer.mjs b/tools/stt-eval/whispercpp-dtw-poc/harness/wer.mjs
index 26276306d..b27f48de5 100644
--- a/tools/stt-eval/whispercpp-dtw-poc/harness/wer.mjs
+++ b/tools/stt-eval/whispercpp-dtw-poc/harness/wer.mjs
@@ -1,28 +1,29 @@
// Word-level WER (Levenshtein) between reference and hypothesis text.
function normalize(s) {
- return s
- .toUpperCase()
- .replace(/[.,!?;:"“”‘’]/g, "")
- .replace(/-/g, " ")
- .split(/\s+/)
- .filter(Boolean);
+ return s
+ .toUpperCase()
+ .replace(/[.,!?;:"“”‘’]/g, "")
+ .replace(/-/g, " ")
+ .split(/\s+/)
+ .filter(Boolean);
}
function wer(ref, hyp) {
- const r = normalize(ref);
- const h = normalize(hyp);
- const n = r.length, m = h.length;
- const d = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
- for (let i = 0; i <= n; i++) d[i][0] = i;
- for (let j = 0; j <= m; j++) d[0][j] = j;
- for (let i = 1; i <= n; i++) {
- for (let j = 1; j <= m; j++) {
- if (r[i - 1] === h[j - 1]) d[i][j] = d[i - 1][j - 1];
- else d[i][j] = 1 + Math.min(d[i - 1][j - 1], d[i - 1][j], d[i][j - 1]);
- }
- }
- const edits = d[n][m];
- return { edits, refWords: n, wer: n === 0 ? 0 : edits / n };
+ const r = normalize(ref);
+ const h = normalize(hyp);
+ const n = r.length,
+ m = h.length;
+ const d = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
+ for (let i = 0; i <= n; i++) d[i][0] = i;
+ for (let j = 0; j <= m; j++) d[0][j] = j;
+ for (let i = 1; i <= n; i++) {
+ for (let j = 1; j <= m; j++) {
+ if (r[i - 1] === h[j - 1]) d[i][j] = d[i - 1][j - 1];
+ else d[i][j] = 1 + Math.min(d[i - 1][j - 1], d[i - 1][j], d[i][j - 1]);
+ }
+ }
+ const edits = d[n][m];
+ return { edits, refWords: n, wer: n === 0 ? 0 : edits / n };
}
const [, , refPath, hypText] = process.argv;