Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(stt): only report a run's timing when every chunk was measured
EtienneLescot08d4a7592371
diff --git a/electron/stt/index.test.ts b/electron/stt/index.test.tsindex 8facfdeb3..35b91567a 100644--- a/electron/stt/index.test.ts+++ b/electron/stt/index.test.ts@@ -141,15 +141,28 @@ describe("SttManager", () => {}});+ // One per chunk of a 200s recording (90s + 90s + 20s), each with a DIFFERENT+ // ratio on purpose. Identical chunks would let a wrong implementation pass:+ // the arithmetic mean of these RTFs is 0.433, while the weighted figure the+ // run should report is 75/200 = 0.375. Only unequal chunks tell them apart.+ const CHUNK_TIMINGS = [+ { elapsedSec: 45, audioSec: 90, rtf: 0.5 },+ { elapsedSec: 18, audioSec: 90, rtf: 0.2 },+ { elapsedSec: 12, audioSec: 20, rtf: 0.6 },+ ];+ const TOTAL_ELAPSED = 75;+ const TOTAL_AUDIO = 200;+/** The default fake answers without timing; this one measures every chunk. */function mockTimedChunks(): void {- fakeWhisperServer.transcribe.mockResolvedValue({+ let call = 0;+ fakeWhisperServer.transcribe.mockImplementation(async () => ({segments: [],wordSegments: [],detectedLanguage: "en",backend: "whispercpp-cpu",- timing: { elapsedSec: 45, audioSec: 90, rtf: 0.5 },- });+ timing: CHUNK_TIMINGS[Math.min(call++, CHUNK_TIMINGS.length - 1)],+ }));}it("sums per-chunk timing into one figure for the whole run", async () => {@@ -161,13 +174,43 @@ describe("SttManager", () => {// Summed, not averaged: chunks differ in length, so the mean of the// per-chunk RTFs would not be the RTF of the run.- const chunkCount = planChunks(samples, 16000).length;- expect(chunkCount).toBeGreaterThan(1);+ expect(planChunks(samples, 16000)).toHaveLength(CHUNK_TIMINGS.length);expect(result.timing).toEqual({- elapsedSec: 45 * chunkCount,- audioSec: 90 * chunkCount,- rtf: 0.5,+ elapsedSec: TOTAL_ELAPSED,+ audioSec: TOTAL_AUDIO,+ rtf: TOTAL_ELAPSED / TOTAL_AUDIO,+ });+ // Nail the distinction down rather than trusting the numbers to differ.+ const mean = CHUNK_TIMINGS.reduce((sum, t) => sum + t.rtf, 0) / CHUNK_TIMINGS.length;+ expect(result.timing?.rtf).not.toBeCloseTo(mean, 3);+ });++ it("reports no run timing at all when one chunk went unmeasured", async () => {+ // A single chunk without a `timing` block is enough to spoil the totals:+ // they would describe 110s of audio for a 200s recording, under a field+ // that says it covers every chunk.+ let call = 0;+ fakeWhisperServer.transcribe.mockImplementation(async () => ({+ segments: [],+ wordSegments: [],+ detectedLanguage: "en",+ backend: "whispercpp-cpu",+ timing: call++ === 1 ? undefined : { elapsedSec: 45, audioSec: 90, rtf: 0.5 },+ }));+ const mgr = new SttManager();+ await mgr.init({ modelsBaseDir: "/tmp/fake-stt-models" });+ const result = await mgr.transcribe({+ samples: new Float32Array(200 * 16000),+ language: "en",});++ expect(result.timing).toBeUndefined();+ // And it says which, rather than claiming nothing was measured at all.+ expect(+ infoSpy.mock.calls.some(([line]) =>+ String(line).includes("timing incomplete (1/3 chunks unmeasured)"),+ ),+ ).toBe(true);});it("logs the backend and the timing of every chunk", async () => {@@ -185,6 +228,8 @@ describe("SttManager", () => {// without arithmetic.expect(chunkLines[0]).toContain("whispercpp-cpu");expect(chunkLines[0]).toContain("90.0s audio in 45.0s (0.50 rtf, 2.0x real-time)");+ // Each line carries ITS OWN chunk's cost, not the running total.+ expect(chunkLines[1]).toContain("90.0s audio in 18.0s (0.20 rtf, 5.0x real-time)");});it("says so when the helper reports no timing at all", async () => {@@ -212,11 +257,11 @@ describe("SttManager", () => {const reported = sink.mock.calls.map(([event]) => event).filter((event) => event.backend !== undefined);- expect(reported).toHaveLength(planChunks(samples, 16000).length);- for (const event of reported) {- expect(event.backend).toBe("whispercpp-cpu");- expect(event.rtf).toBeCloseTo(0.5);- }+ expect(reported).toHaveLength(CHUNK_TIMINGS.length);+ for (const event of reported) expect(event.backend).toBe("whispercpp-cpu");+ // Cumulative and weighted at every step — 45/90, then 63/180, then 75/200 —+ // which is what makes the figure settle instead of bouncing per chunk.+ expect(reported.map((e) => e.rtf)).toEqual([45 / 90, 63 / 180, 75 / 200]);});it("warns once per run — not once per chunk — that it landed on CPU", async () => {diff --git a/electron/stt/index.ts b/electron/stt/index.tsindex b600c0cc1..c250ea4ac 100644--- a/electron/stt/index.ts+++ b/electron/stt/index.ts@@ -254,6 +254,7 @@ export class SttManager {let elapsedSec = 0;let audioSec = 0;let timedChunks = 0;+ let untimedChunks = 0;// The CPU verdict is worth saying once per run, not once per chunk.let warnedCpu = false;// Only the first chunk auto-detects; every later chunk is forced onto the@@ -330,6 +331,8 @@ export class SttManager {elapsedSec += result.timing.elapsedSec;audioSec += result.timing.audioSec;timedChunks++;+ } else {+ untimedChunks++;}const runRtf = audioSec > 0 ? elapsedSec / audioSec : undefined;// Through `console.*` on purpose: that is what the main-process ring@@ -364,13 +367,24 @@ export class SttManager {});}+ // A total has to cover everything it claims to total. Let one chunk go+ // unmeasured and these sums describe a SHORTER recording than the one that+ // was actually transcribed — under a field documented as covering every+ // chunk. So an incomplete run reports no timing rather than partial timing.+ //+ // The per-chunk `rtf` emitted above is deliberately not held to this: it is+ // a RATIO, not a total, and stays honest over whatever subset reported.const timing: SttTiming | undefined =- timedChunks > 0 && audioSec > 0+ timedChunks > 0 && untimedChunks === 0 && audioSec > 0? { elapsedSec, audioSec, rtf: elapsedSec / audioSec }: undefined;console.info(`[stt] done on ${backend}: ${chunks.length} chunk(s), ` +- (timing ? formatTiming(timing) : "no timing reported"),+ (timing+ ? formatTiming(timing)+ : untimedChunks === chunks.length+ ? "no timing reported"+ : `timing incomplete (${untimedChunks}/${chunks.length} chunks unmeasured)`),);return {segments,diff --git a/electron/stt/transcriptionContract.ts b/electron/stt/transcriptionContract.tsindex 68db62cc6..cbce5a141 100644--- a/electron/stt/transcriptionContract.ts+++ b/electron/stt/transcriptionContract.ts@@ -96,6 +96,10 @@ export interface SttStatusEvent {* for the chunk that just landed. Per-chunk values swing with how much speech* a chunk happens to hold, and a figure that jumps every 90s reads as noise* rather than as progress.+ *+ * Computed over the chunks that reported timing. Unlike+ * `SttTranscribeResponse.timing` this is a ratio rather than a total, so it+ * stays meaningful even when a chunk reports nothing.*/rtf?: number;}@@ -116,7 +120,11 @@ export interface SttTranscribeResponse {wordSegments: SttWordSegment[];detectedLanguage: string;backend: SttBackend;- /** Summed over every chunk of this request; absent if no chunk reported timing. */+ /**+ * Summed over every chunk of this request — and absent unless ALL of them+ * reported, because a total that quietly skips a chunk describes a shorter+ * recording than the one that was transcribed.+ */timing?: SttTiming;}diff --git a/electron/stt/whisperServer.test.ts b/electron/stt/whisperServer.test.tsindex b8851157e..c3637c978 100644--- a/electron/stt/whisperServer.test.ts+++ b/electron/stt/whisperServer.test.ts@@ -229,6 +229,22 @@ describe("WhisperServerManager", () => {expect(result.timing).toEqual({ elapsedSec: 4, audioSec: 8, rtf: 0.5 });});+ // Durations no clock could produce. Letting these through would put a bogus+ // figure into the run totals in SttManager, where nothing downstream could+ // tell it from a real measurement.+ it.each([+ ["negative elapsed", { elapsed_s: -1, audio_s: 8 }],+ ["zero audio", { elapsed_s: 4, audio_s: 0 }],+ ["negative audio", { elapsed_s: 4, audio_s: -8 }],+ ])("rejects a timing block with %s", async (_label, timing) => {+ const result = await transcribeWith({+ segments: [],+ backend: "whispercpp-cpu",+ timing,+ });+ expect(result.timing).toBeNull();+ });+it("rejects a timing block with no usable durations", async () => {const result = await transcribeWith({segments: [],diff --git a/electron/stt/whisperServer.ts b/electron/stt/whisperServer.tsindex 5eb43fb19..415a5568a 100644--- a/electron/stt/whisperServer.ts+++ b/electron/stt/whisperServer.ts@@ -473,19 +473,22 @@ export class WhisperServerManager {* `rtf` is recomputed from the two durations whenever the helper didn't send* a usable one. It is derived data, and a NaN surviving this far would reach* the UI as "NaN x real-time".+ *+ * Durations no clock could have produced are treated as a junk block, not as+ * a slow one: `steady_clock` cannot run backwards, and a chunk holding no+ * audio has nothing to measure. Rejecting them here is what keeps a bad value+ * out of `SttManager`'s run totals, where it would quietly distort the figure+ * the whole recording is reported against.*/private toTiming(raw: WhisperJsonTiming | undefined): SttTiming | null {if (!raw || typeof raw !== "object") return null;const elapsedSec = this.toSec(raw.elapsed_s, Number.NaN);const audioSec = this.toSec(raw.audio_s, Number.NaN);- if (!Number.isFinite(elapsedSec) || !Number.isFinite(audioSec)) return null;+ if (!Number.isFinite(elapsedSec) || elapsedSec < 0) return null;+ // Also the divisor below, so this doubles as the divide-by-zero guard.+ if (!Number.isFinite(audioSec) || audioSec <= 0) return null;const reported = this.toSec(raw.rtf, Number.NaN);- const rtf =- Number.isFinite(reported) && reported > 0- ? reported- : audioSec > 0- ? elapsedSec / audioSec- : 0;+ const rtf = Number.isFinite(reported) && reported > 0 ? reported : elapsedSec / audioSec;return { elapsedSec, audioSec, rtf };}diff --git a/src/components/ai-edition/TranscriptionStatus.test.tsx b/src/components/ai-edition/TranscriptionStatus.test.tsxnew file mode 100644index 000000000..47f1303e4--- /dev/null+++ b/src/components/ai-edition/TranscriptionStatus.test.tsx@@ -0,0 +1,104 @@+// @vitest-environment jsdom+import "@testing-library/jest-dom";+import { render } from "@testing-library/react";+import { describe, expect, it, vi } from "vitest";++// The translator returns the key: an assertion reads better against a key than+// against a sentence that moves every time the copy is revised.+vi.mock("@/contexts/I18nContext", () => ({+ useScopedT: () => (key: string) => key,+}));++import type { AssetTranscriptionView } from "@/lib/ai-edition/transcription/status";+import { TranscriptionStatusDot, useTranscriptionLabel } from "./TranscriptionStatus";++/** Renders the shared label so the hook can be asserted as plain text. */+function Label({ view }: { view: AssetTranscriptionView }) {+ return <span data-testid="label">{useTranscriptionLabel()(view)}</span>;+}++function running(extra: Partial<AssetTranscriptionView> = {}): AssetTranscriptionView {+ return {+ assetId: "a",+ status: "running",+ progress: { completedSec: 45, totalSec: 100 },+ ...extra,+ };+}++function labelOf(view: AssetTranscriptionView): string {+ return render(<Label view={view} />).getByTestId("label").textContent ?? "";+}++describe("useTranscriptionLabel telemetry suffix", () => {+ // The whole point of the change: a run on the slow path says so, in the one+ // string all three status surfaces render.+ it("names the CPU path and the speed while transcribing", () => {+ expect(labelOf(running({ backend: "whispercpp-cpu", rtf: 1.1 }))).toBe(+ "mediaStage.transcribing 45% · CPU · 0.9×",+ );+ });++ // A healthy GPU run gets the speed but no backend name — labelling every+ // successful run "Vulkan" would be noise, and only the CPU case is actionable.+ it("shows the speed but not the backend on a GPU run", () => {+ expect(labelOf(running({ backend: "whispercpp-vulkan", rtf: 0.5 }))).toBe(+ "mediaStage.transcribing 45% · 2.0×",+ );+ });++ // Regression guard for the helper binary that predates the `timing` field:+ // with nothing reported the label must be exactly what it always was, not+ // "0.0×" and not a stray separator.+ it("is unchanged when the engine reports no timing", () => {+ expect(labelOf(running())).toBe("mediaStage.transcribing 45%");+ });++ // Chunk progress can be absent while the run is still starting up.+ it("drops the percentage but keeps the telemetry without progress", () => {+ expect(labelOf(running({ progress: undefined, backend: "whispercpp-cpu" }))).toBe(+ "mediaStage.transcribing · CPU",+ );+ });++ // The model download has its own words and no device to report yet.+ it("leaves the model-download phase alone", () => {+ expect(labelOf(running({ phase: "loading-model", backend: "whispercpp-cpu", rtf: 1.1 }))).toBe(+ "mediaStage.downloadingModel",+ );+ });+});++describe("TranscriptionStatusDot", () => {+ // "CPU" in the label is terse by necessity; the tooltip is where the cost is+ // spelled out. It has to be a <title> CHILD because lucide renders an <svg>,+ // which has no tooltip-bearing `title` attribute.+ it("explains the CPU cost in the spinner's SVG title", () => {+ const { container } = render(+ <TranscriptionStatusDot view={running({ backend: "whispercpp-cpu", rtf: 1.1 })} />,+ );+ const title = container.querySelector("svg > title");+ expect(title?.textContent).toBe(+ "mediaStage.transcribing 45% · CPU · 0.9× — mediaStage.cpuBackendHint",+ );+ });++ it("uses the plain label as the title on a GPU run", () => {+ const { container } = render(+ <TranscriptionStatusDot view={running({ backend: "whispercpp-vulkan", rtf: 0.5 })} />,+ );+ expect(container.querySelector("svg > title")?.textContent).toBe(+ "mediaStage.transcribing 45% · 2.0×",+ );+ });++ // A settled asset renders the dot, not the spinner — the tooltip lives on the+ // `title` attribute there, and no backend is in play.+ it("falls back to the dot once the run is over", () => {+ const { container } = render(+ <TranscriptionStatusDot view={{ assetId: "a", status: "ready" }} />,+ );+ expect(container.querySelector("svg")).toBeNull();+ expect(container.querySelector("span")).toHaveAttribute("title", "mediaStage.transcriptReady");+ });+});diff --git a/technical-documentation/architecture/transcription-and-captions.md b/technical-documentation/architecture/transcription-and-captions.mdindex 4a4288e28..02bf9ae8b 100644--- a/technical-documentation/architecture/transcription-and-captions.md+++ b/technical-documentation/architecture/transcription-and-captions.md@@ -649,7 +649,7 @@ it deletes datadisplayed it verbatim, and `transcribe.ts` wrote it onto`AxcutTranscript.language`. It now reports `whisper_full_lang_id()` — thedetected language under `"auto"`, the forced one otherwise.-- **No CUDA build.** Vulkan already accelerates NVIDIA on Windows and+- **CUDA not built by default.** Vulkan already accelerates NVIDIA on Windows andLinux. CMake still accepts `OSC_ENABLE_CUDA=ON`, so a CUDA-enabledhelper can be built by passing that through to `cmake` — it installsunder the ordinary `whisper-stt-server` name and reports