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
feat(stt): show real transcription progress instead of an endless spinner
Etienne Lescotd08e04068494
diff --git a/src/components/ai-edition/TranscriptionStatus.tsx b/src/components/ai-edition/TranscriptionStatus.tsxindex 5e17bd276..cd7618b61 100644--- a/src/components/ai-edition/TranscriptionStatus.tsx+++ b/src/components/ai-edition/TranscriptionStatus.tsx@@ -9,7 +9,10 @@import { Loader2 } from "lucide-react";import { useScopedT } from "@/contexts/I18nContext";-import type { AssetTranscriptionView } from "@/lib/ai-edition/transcription/status";+import {+ type AssetTranscriptionView,+ progressFraction,+} from "@/lib/ai-edition/transcription/status";/** Human-readable state of one asset's transcript, in the user's language. */export function useTranscriptionLabel(): (view: AssetTranscriptionView) => string {@@ -20,8 +23,16 @@ export function useTranscriptionLabel(): (view: AssetTranscriptionView) => strinreturn t("mediaStage.transcriptReady");case "queued":return t("mediaStage.pendingTranscription");- case "running":- return t("mediaStage.transcribing");+ case "running": {+ // Transcribing a long recording runs for minutes. A bare+ // "Transcribing…" for that whole time is indistinguishable from a+ // hang, so append the percentage as soon as the main process reports+ // chunk progress — and only then (see `TranscriptionProgress`).+ const fraction = progressFraction(view.progress);+ return fraction === null+ ? t("mediaStage.transcribing")+ : `${t("mediaStage.transcribing")} ${Math.round(fraction * 100)}%`;+ }case "empty":return t("mediaStage.noSpeechDetected");case "failed":@@ -79,3 +90,39 @@ export function TranscriptionStatusDot({/>);}++/**+ * Determinate progress bar for a running transcription. Renders nothing unless+ * the job actually reports measurable progress — a job that is queued,+ * extracting audio or downloading the model has no meaningful fraction, and a+ * bar pinned at 0% reads as "stuck" where the spinner reads as "working".+ */+export function TranscriptionProgressBar({ view }: { view: AssetTranscriptionView }) {+ const label = useTranscriptionLabel()(view);+ const fraction = view.status === "running" ? progressFraction(view.progress) : null;+ if (fraction === null) return null;+ return (+ <div+ role="progressbar"+ aria-label={label}+ aria-valuemin={0}+ aria-valuemax={100}+ aria-valuenow={Math.round(fraction * 100)}+ style={{+ height: 4,+ borderRadius: 999,+ background: "var(--surface-3)",+ overflow: "hidden",+ }}+ >+ <div+ style={{+ height: "100%",+ width: `${fraction * 100}%`,+ background: "var(--accent)",+ transition: "width 200ms linear",+ }}+ />+ </div>+ );+}diff --git a/src/components/ai-edition/v4/MediaStage.tsx b/src/components/ai-edition/v4/MediaStage.tsxindex 8c4bca65c..cd3e2e424 100644--- a/src/components/ai-edition/v4/MediaStage.tsx+++ b/src/components/ai-edition/v4/MediaStage.tsx@@ -14,7 +14,11 @@ import type {AssetTranscriptionView,} from "@/lib/ai-edition/transcription/status";import { formatBytes } from "@/utils/formatBytes";-import { TranscriptionStatusDot, useTranscriptionLabel } from "../TranscriptionStatus";+import {+ TranscriptionProgressBar,+ TranscriptionStatusDot,+ useTranscriptionLabel,+} from "../TranscriptionStatus";import styles from "./EditorShellV4.module.css";const ASSET_MIME = "application/x-axcut-asset";@@ -268,6 +272,11 @@ export function MediaStage() {</span></div>+ {/* Renders itself away unless the run reports measurable progress. */}+ <div style={{ margin: "-8px 0 16px" }}>+ <TranscriptionProgressBar view={selectedTranscription} />+ </div>+{selectedTranscription.failure ? (<pstyle={{diff --git a/src/lib/ai-edition/store/transcriptionStore.ts b/src/lib/ai-edition/store/transcriptionStore.tsindex 9d765afc3..1cee92d11 100644--- a/src/lib/ai-edition/store/transcriptionStore.ts+++ b/src/lib/ai-edition/store/transcriptionStore.ts@@ -40,6 +40,7 @@ import {type TranscriptGate,type TranscriptionFailure,type TranscriptionPhase,+ type TranscriptionProgress,transcriptRelevantAssetIds,} from "../transcription/status";import { useProjectStore } from "./projectStore";@@ -50,6 +51,8 @@ export interface TranscriptionJob {* finishes after the user asked for another one cannot clear its successor. */runId?: number;phase?: TranscriptionPhase;+ /** Chunk progress while transcribing; absent until the first chunk lands. */+ progress?: TranscriptionProgress;/** `"auto"` unless the user forced a language from the media card. */language: string;failure?: TranscriptionFailure;@@ -273,7 +276,7 @@ function failRemainingQueue(projectId: string, failure: TranscriptionFailure): vfor (const assetId of queued) {const job = jobs[assetId];if (job?.status !== "queued") continue;- jobs[assetId] = { ...job, status: "failed", phase: undefined, failure };+ jobs[assetId] = { ...job, status: "failed", phase: undefined, progress: undefined, failure };}return { jobs };});@@ -365,7 +368,19 @@ async function runJob(assetId: string, job: TranscriptionJob): Promise<void> {const transcript = await transcribeAsset(doc, assetId, {language: job.language,signal: controller.signal,- onStatus: (phase) => patchJob(assetId, runId, { phase: phase as TranscriptionPhase }),+ // `TranscribeStatus` and `TranscriptionPhase` are the same vocabulary on+ // purpose (see status.ts), so this no longer needs a cast. `progress`+ // only arrives during "transcribing"; carrying it through undefined the+ // rest of the time is what lets the UI fall back to a spinner instead+ // of a bar frozen at 0%.+ onStatus: (status) =>+ patchJob(assetId, runId, {+ phase: status.phase,+ progress:+ status.completedSec !== undefined && status.totalSec !== undefined+ ? { completedSec: status.completedSec, totalSec: status.totalSec }+ : undefined,+ }),});if (controller.signal.aborted) {dropJob(assetId, runId);@@ -400,7 +415,7 @@ async function runJob(assetId: string, job: TranscriptionJob): Promise<void> {}if (!isCurrentRun(assetId, runId)) return; // superseded by a newer requestconst failure = classifyTranscriptionError(error);- patchJob(assetId, runId, { status: "failed", phase: undefined, failure });+ patchJob(assetId, runId, { status: "failed", phase: undefined, progress: undefined, failure });flushSettleWaiters(assetId);await persistPermanentFailure(projectId, assetId, failure);// A transient failure is about the ENGINE, not about this media: the modeldiff --git a/src/lib/ai-edition/transcription/status.test.ts b/src/lib/ai-edition/transcription/status.test.tsindex adc21cd35..00d8864e1 100644--- a/src/lib/ai-edition/transcription/status.test.ts+++ b/src/lib/ai-edition/transcription/status.test.ts@@ -5,6 +5,7 @@ import {classifyTranscriptionError,deriveAssetStatus,isPermanentFailure,+ progressFraction,resolveTranscriptGate,transcriptHasSpeech,transcriptRelevantAssetIds,@@ -93,6 +94,30 @@ describe("deriveAssetStatus", () => {expect(derived).toEqual({ assetId: "asset_1", status: "running", phase: "transcribing" });});+ it("carries chunk progress through to the view", () => {+ const derived = deriveAssetStatus({+ assetId: "asset_1",+ job: {+ status: "running",+ phase: "transcribing",+ progress: { completedSec: 90, totalSec: 300 },+ },+ });+ expect(derived.progress).toEqual({ completedSec: 90, totalSec: 300 });+ expect(progressFraction(derived.progress)).toBeCloseTo(0.3);+ });++ it("leaves progress absent while nothing measurable is running", () => {+ // Audio extraction and the model download have no fraction to report; the+ // UI must get `undefined` so it keeps the spinner instead of a 0% bar.+ const derived = deriveAssetStatus({+ assetId: "asset_1",+ job: { status: "running", phase: "extracting-audio" },+ });+ expect(derived.progress).toBeUndefined();+ expect(progressFraction(derived.progress)).toBeNull();+ });+it("reports ready from the document, with no job at all", () => {expect(deriveAssetStatus({ assetId: "asset_1", transcript: transcript("asset_1", ["hello"]) })diff --git a/src/lib/ai-edition/transcription/status.ts b/src/lib/ai-edition/transcription/status.tsindex fced8390a..f05454b66 100644--- a/src/lib/ai-edition/transcription/status.ts+++ b/src/lib/ai-edition/transcription/status.ts@@ -17,8 +17,28 @@ export interface TranscriptionFailure {message: string;}-/** Which half of the pipeline a running job is in (mirrors `TranscribeAssetOptions.onStatus`). */-export type TranscriptionPhase = "extracting-audio" | "transcribing";+/** Which part of the pipeline a running job is in (mirrors `TranscribeAssetOptions.onStatus`). */+export type TranscriptionPhase = "extracting-audio" | "loading-model" | "transcribing";++/**+ * How far a running transcription has got, in seconds of audio.+ *+ * Only the `"transcribing"` phase reports this, and only once the main process+ * starts landing chunks — audio extraction and the first-run model download+ * have nothing to measure. Absent means "running, no measurable progress", not+ * "zero": the UI must fall back to an indeterminate spinner rather than render+ * a bar stuck at 0%.+ */+export interface TranscriptionProgress {+ completedSec: number;+ totalSec: number;+}++/** `0..1`, or null when the job reports no measurable progress. */+export function progressFraction(progress: TranscriptionProgress | undefined): number | null {+ if (!progress || !(progress.totalSec > 0)) return null;+ return Math.min(1, Math.max(0, progress.completedSec / progress.totalSec));+}/*** A media that has no audio track (or one Whisper cannot read) will fail the@@ -72,6 +92,7 @@ export interface AssetTranscriptionView {assetId: string;status: AssetTranscriptionStatus;phase?: TranscriptionPhase;+ progress?: TranscriptionProgress;failure?: TranscriptionFailure;}@@ -79,6 +100,7 @@ export interface AssetTranscriptionView {export interface TranscriptionJobLike {status: "queued" | "running" | "failed";phase?: TranscriptionPhase;+ progress?: TranscriptionProgress;failure?: TranscriptionFailure;}@@ -122,7 +144,7 @@ export function deriveAssetStatus(input: {}): AssetTranscriptionView {const { assetId, job, transcript, persistedFailure } = input;if (job && job.status !== "failed") {- return { assetId, status: job.status, phase: job.phase };+ return { assetId, status: job.status, phase: job.phase, progress: job.progress };}if (transcript) {return {