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): wire the language list into the picker that's actually live
EtienneLescot05eb06b4d895
diff --git a/src/components/ai-edition/Modals.tsx b/src/components/ai-edition/Modals.tsxindex 4a6c740b6..db393031d 100644--- a/src/components/ai-edition/Modals.tsx+++ b/src/components/ai-edition/Modals.tsx@@ -25,48 +25,15 @@ import { toFileUrl } from "@/components/video-editor/projectPersistence";import type { CropRegion } from "@/components/video-editor/types";import { useI18n, useScopedT } from "@/contexts/I18nContext";import { toAxcutTranscriptDsl } from "@/lib/ai-edition/document/transcribe";-import {- type AxcutClip,- type AxcutTranscript,- TRANSCRIPT_LANGUAGE_CODES,- TRANSCRIPT_LANGUAGE_NAMES,- type TranscriptLanguageCode,-} from "@/lib/ai-edition/schema";+import type { AxcutClip, AxcutTranscript, TranscriptLanguageCode } from "@/lib/ai-edition/schema";import { formatSec, formatSeconds } from "@/lib/ai-edition/timeline/format";+import {+ languageLabel,+ sortedLanguageOptions,+} from "@/lib/ai-edition/transcription/languageLabels";import styles from "./NewEditorShell.module.css";import type { VideoSource } from "./VirtualPreview";-const languageDisplayNamesCache = new Map<string, Intl.DisplayNames>();--function languageDisplayNamesFor(locale: string): Intl.DisplayNames | null {- const cached = languageDisplayNamesCache.get(locale);- if (cached) return cached;- try {- const names = new Intl.DisplayNames([locale], { type: "language" });- languageDisplayNamesCache.set(locale, names);- return names;- } catch {- return null;- }-}--/**- * Localized name for a whisper.cpp language code, e.g. "jw" -> "Javanese" in- * an English UI, "japonais" in a French one. Falls back to whisper's own- * English name (`TRANSCRIPT_LANGUAGE_NAMES`) when the active locale's ICU- * data can't resolve one — `Intl.DisplayNames` echoes the input code back- * rather than throwing when it doesn't recognize it.- */-function languageLabel(code: Exclude<TranscriptLanguageCode, "auto">, locale: string): string {- try {- const resolved = languageDisplayNamesFor(locale)?.of(code);- if (resolved && resolved.toLowerCase() !== code.toLowerCase()) return resolved;- } catch {- // Malformed/unsupported subtag for this Intl implementation.- }- return TRANSCRIPT_LANGUAGE_NAMES[code];-}-interface BaseModalProps {open: boolean;onClose: () => void;@@ -1586,17 +1553,10 @@ export function SourceTranscriptModal({if (open) setRegenLang((transcript?.language as TranscriptLanguageCode) ?? "auto");}, [open, transcript?.language]);- // Auto pinned first; the rest sorted by localized name so a 100-language- // list is scannable instead of ordered by whisper's internal language id.- const regenLanguageOptions = useMemo(() => {- const collator = new Intl.Collator(locale);- const rest = TRANSCRIPT_LANGUAGE_CODES.filter(- (code): code is Exclude<TranscriptLanguageCode, "auto"> => code !== "auto",- )- .map((code) => ({ code, label: languageLabel(code, locale) }))- .sort((a, b) => collator.compare(a.label, b.label));- return [{ code: "auto" as const, label: t("mediaStage.auto") }, ...rest];- }, [locale, t]);+ const regenLanguageOptions = useMemo(+ () => sortedLanguageOptions(locale, t("mediaStage.auto")),+ [locale, t],+ );useEffect(() => {if (!open) {@@ -1893,7 +1853,9 @@ export function SourceTranscriptModal({border: "1px solid color-mix(in srgb, var(--success) 22%, transparent)",}}>- {t("mediaStage.detectedLanguage", { language: detectedLanguage })}+ {t("mediaStage.detectedLanguage", {+ language: languageLabel(detectedLanguage, locale),+ })}</span>) : null}</div>diff --git a/src/components/ai-edition/v4/MediaStage.tsx b/src/components/ai-edition/v4/MediaStage.tsxindex e69ff3452..f844bfca4 100644--- a/src/components/ai-edition/v4/MediaStage.tsx+++ b/src/components/ai-edition/v4/MediaStage.tsx@@ -1,14 +1,18 @@import { ArrowDown, Film, Plus, RotateCw, Search, X } from "lucide-react";import { useMemo, useState } from "react";import { toast } from "sonner";-import { useScopedT } from "@/contexts/I18nContext";-import type { AxcutAsset } from "@/lib/ai-edition/schema";+import { useI18n, useScopedT } from "@/contexts/I18nContext";+import type { AxcutAsset, TranscriptLanguageCode } from "@/lib/ai-edition/schema";import { useProjectStore } from "@/lib/ai-edition/store/projectStore";import {useAssetTranscriptions,useTranscriptionStore,} from "@/lib/ai-edition/store/transcriptionStore";import { formatSeconds } from "@/lib/ai-edition/timeline/format";+import {+ languageLabel,+ sortedLanguageOptions,+} from "@/lib/ai-edition/transcription/languageLabels";import type {AssetTranscriptionStatus,AssetTranscriptionView,@@ -49,6 +53,7 @@ export function MediaStage({onAddToTimeline: (assetId: string) => Promise<void>;}) {const t = useScopedT("editor");+ const { locale } = useI18n();const projectId = useProjectStore((s) => s.projectId);const document = useProjectStore((s) => s.document);const addAsset = useProjectStore((s) => s.addAsset);@@ -62,7 +67,11 @@ export function MediaStage({const [busy, setBusy] = useState(false);const [selectedId, setSelectedId] = useState<string | null>(null);const [detailOpen, setDetailOpen] = useState(false);- const [lang, setLang] = useState("auto");+ const [lang, setLang] = useState<TranscriptLanguageCode>("auto");+ const regenLanguageOptions = useMemo(+ () => sortedLanguageOptions(locale, t("mediaStage.auto")),+ [locale, t],+ );const assets = document?.assets ?? [];const filtered = useMemo(@@ -335,7 +344,9 @@ export function MediaStage({fontWeight: 600,}}>- {t("mediaStage.detectedLanguage", { language: transcript.language })}+ {t("mediaStage.detectedLanguage", {+ language: languageLabel(transcript.language, locale),+ })}</span>) : null}</div>@@ -372,7 +383,7 @@ export function MediaStage({<div style={{ display: "flex", gap: 8 }}><selectvalue={lang}- onChange={(e) => setLang(e.target.value)}+ onChange={(e) => setLang(e.target.value as TranscriptLanguageCode)}style={{flex: 1,minWidth: 0,@@ -387,10 +398,11 @@ export function MediaStage({outline: "none",}}>- <option value="auto">{t("mediaStage.auto")}</option>- <option value="en">English</option>- <option value="fr">Français</option>- <option value="es">Español</option>+ {regenLanguageOptions.map(({ code, label }) => (+ <option key={code} value={code}>+ {label}+ </option>+ ))}</select><buttontype="button"diff --git a/src/lib/ai-edition/schema/index.ts b/src/lib/ai-edition/schema/index.tsindex 8fe33fc1a..dd6936fde 100644--- a/src/lib/ai-edition/schema/index.ts+++ b/src/lib/ai-edition/schema/index.ts@@ -816,8 +816,14 @@ export const chatInputSchema = z.object({// (`src/whisper.cpp`, verified against the tag `nix/whisper-stt.nix` pins —// v1.9.1) — `wparams.language` in// electron/native/whisper-stt/src/main.cpp forwards the code verbatim, so a-// value outside this list fails to resolve a language id there. The UI's-// "Regenerate as" picker (Modals.tsx) is the only current consumer.+// value outside this list fails to resolve a language id there. "auto" is+// always index 0 — code that needs "every real language, no sentinel" relies+// on that (see `WhisperLanguageCode` below) rather than filtering it out.+// Consumed by both "Regenerate as" pickers: `MediaStage.tsx` (the one+// actually mounted by `NewEditorShell`) and `Modals.tsx`'s+// `SourceTranscriptModal` (currently unreachable — `LeftPanel` is only ever+// mounted with `active="chat"` — but kept correct rather than deleted, since+// nothing marks it dead code and a test or a future rewire could reach it).export const TRANSCRIPT_LANGUAGE_CODES = ["auto","en",@@ -924,117 +930,6 @@ export const TRANSCRIPT_LANGUAGE_CODES = [export const transcriptLanguageSchema = z.enum(TRANSCRIPT_LANGUAGE_CODES);-/**- * English fallback name per code, from whisper.cpp's own `g_lang` table.- * The UI prefers `Intl.DisplayNames` in the active locale and falls back to- * this when that can't resolve a name (e.g. an unusual code on an older ICU).- */-export const TRANSCRIPT_LANGUAGE_NAMES: Record<- Exclude<(typeof TRANSCRIPT_LANGUAGE_CODES)[number], "auto">,- string-> = {- en: "English",- zh: "Chinese",- de: "German",- es: "Spanish",- ru: "Russian",- ko: "Korean",- fr: "French",- ja: "Japanese",- pt: "Portuguese",- tr: "Turkish",- pl: "Polish",- ca: "Catalan",- nl: "Dutch",- ar: "Arabic",- sv: "Swedish",- it: "Italian",- id: "Indonesian",- hi: "Hindi",- fi: "Finnish",- vi: "Vietnamese",- he: "Hebrew",- uk: "Ukrainian",- el: "Greek",- ms: "Malay",- cs: "Czech",- ro: "Romanian",- da: "Danish",- hu: "Hungarian",- ta: "Tamil",- no: "Norwegian",- th: "Thai",- ur: "Urdu",- hr: "Croatian",- bg: "Bulgarian",- lt: "Lithuanian",- la: "Latin",- mi: "Maori",- ml: "Malayalam",- cy: "Welsh",- sk: "Slovak",- te: "Telugu",- fa: "Persian",- lv: "Latvian",- bn: "Bengali",- sr: "Serbian",- az: "Azerbaijani",- sl: "Slovenian",- kn: "Kannada",- et: "Estonian",- mk: "Macedonian",- br: "Breton",- eu: "Basque",- is: "Icelandic",- hy: "Armenian",- ne: "Nepali",- mn: "Mongolian",- bs: "Bosnian",- kk: "Kazakh",- sq: "Albanian",- sw: "Swahili",- gl: "Galician",- mr: "Marathi",- pa: "Punjabi",- si: "Sinhala",- km: "Khmer",- sn: "Shona",- yo: "Yoruba",- so: "Somali",- af: "Afrikaans",- oc: "Occitan",- ka: "Georgian",- be: "Belarusian",- tg: "Tajik",- sd: "Sindhi",- gu: "Gujarati",- am: "Amharic",- yi: "Yiddish",- lo: "Lao",- uz: "Uzbek",- fo: "Faroese",- ht: "Haitian Creole",- ps: "Pashto",- tk: "Turkmen",- nn: "Norwegian Nynorsk",- mt: "Maltese",- sa: "Sanskrit",- lb: "Luxembourgish",- my: "Myanmar",- bo: "Tibetan",- tl: "Tagalog",- mg: "Malagasy",- as: "Assamese",- tt: "Tatar",- haw: "Hawaiian",- ln: "Lingala",- ha: "Hausa",- ba: "Bashkir",- jw: "Javanese",- su: "Sundanese",- yue: "Cantonese",-};-export type AxcutWord = z.infer<typeof wordSchema>;export type AxcutTranscriptSegment = z.infer<typeof transcriptSegmentSchema>;export type AxcutTranscript = z.infer<typeof transcriptSchema>;@@ -1056,6 +951,8 @@ export type CreateProjectInput = z.infer<typeof createProjectInputSchema>;export type AddAssetInput = z.infer<typeof addAssetInputSchema>;export type ChatInput = z.infer<typeof chatInputSchema>;export type TranscriptLanguageCode = z.infer<typeof transcriptLanguageSchema>;+/** A real whisper.cpp language code — `TranscriptLanguageCode` minus the "auto" detection sentinel. */+export type WhisperLanguageCode = Exclude<TranscriptLanguageCode, "auto">;export function createEmptyDocument(input: CreateProjectInput & { projectId: string; createdAt?: string },diff --git a/src/lib/ai-edition/transcription/languageLabels.ts b/src/lib/ai-edition/transcription/languageLabels.tsnew file mode 100644index 000000000..02f2f08e8--- /dev/null+++ b/src/lib/ai-edition/transcription/languageLabels.ts@@ -0,0 +1,182 @@+// Turns a whisper.cpp language code into text a user can read. Shared by+// every "Regenerate as" picker and detected-language pill so they can't+// disagree with each other the way a hand-duplicated label map would.+import {+ TRANSCRIPT_LANGUAGE_CODES,+ type TranscriptLanguageCode,+ type WhisperLanguageCode,+} from "../schema";++/**+ * English fallback name per code, from whisper.cpp's own `g_lang` table.+ * `languageLabel` prefers `Intl.DisplayNames` in the active locale and falls+ * back to this when that can't resolve a name (e.g. an unusual code on an+ * older ICU).+ */+const ENGLISH_NAMES: Record<WhisperLanguageCode, string> = {+ en: "English",+ zh: "Chinese",+ de: "German",+ es: "Spanish",+ ru: "Russian",+ ko: "Korean",+ fr: "French",+ ja: "Japanese",+ pt: "Portuguese",+ tr: "Turkish",+ pl: "Polish",+ ca: "Catalan",+ nl: "Dutch",+ ar: "Arabic",+ sv: "Swedish",+ it: "Italian",+ id: "Indonesian",+ hi: "Hindi",+ fi: "Finnish",+ vi: "Vietnamese",+ he: "Hebrew",+ uk: "Ukrainian",+ el: "Greek",+ ms: "Malay",+ cs: "Czech",+ ro: "Romanian",+ da: "Danish",+ hu: "Hungarian",+ ta: "Tamil",+ no: "Norwegian",+ th: "Thai",+ ur: "Urdu",+ hr: "Croatian",+ bg: "Bulgarian",+ lt: "Lithuanian",+ la: "Latin",+ mi: "Maori",+ ml: "Malayalam",+ cy: "Welsh",+ sk: "Slovak",+ te: "Telugu",+ fa: "Persian",+ lv: "Latvian",+ bn: "Bengali",+ sr: "Serbian",+ az: "Azerbaijani",+ sl: "Slovenian",+ kn: "Kannada",+ et: "Estonian",+ mk: "Macedonian",+ br: "Breton",+ eu: "Basque",+ is: "Icelandic",+ hy: "Armenian",+ ne: "Nepali",+ mn: "Mongolian",+ bs: "Bosnian",+ kk: "Kazakh",+ sq: "Albanian",+ sw: "Swahili",+ gl: "Galician",+ mr: "Marathi",+ pa: "Punjabi",+ si: "Sinhala",+ km: "Khmer",+ sn: "Shona",+ yo: "Yoruba",+ so: "Somali",+ af: "Afrikaans",+ oc: "Occitan",+ ka: "Georgian",+ be: "Belarusian",+ tg: "Tajik",+ sd: "Sindhi",+ gu: "Gujarati",+ am: "Amharic",+ yi: "Yiddish",+ lo: "Lao",+ uz: "Uzbek",+ fo: "Faroese",+ ht: "Haitian Creole",+ ps: "Pashto",+ tk: "Turkmen",+ nn: "Norwegian Nynorsk",+ mt: "Maltese",+ sa: "Sanskrit",+ lb: "Luxembourgish",+ my: "Myanmar",+ bo: "Tibetan",+ tl: "Tagalog",+ mg: "Malagasy",+ as: "Assamese",+ tt: "Tatar",+ haw: "Hawaiian",+ ln: "Lingala",+ ha: "Hausa",+ ba: "Bashkir",+ jw: "Javanese",+ su: "Sundanese",+ yue: "Cantonese",+};++// Caches both success AND failure (`null`) per locale, so a locale whose ICU+// data can't build a language `Intl.DisplayNames` (e.g. a small-icu runtime)+// pays the throwing constructor once per locale, not once per language code.+const displayNamesCache = new Map<string, Intl.DisplayNames | null>();++function displayNamesFor(locale: string): Intl.DisplayNames | null {+ if (displayNamesCache.has(locale)) return displayNamesCache.get(locale) ?? null;+ let names: Intl.DisplayNames | null;+ try {+ names = new Intl.DisplayNames([locale], { type: "language" });+ } catch {+ names = null;+ }+ displayNamesCache.set(locale, names);+ return names;+}++/**+ * Localized name for a whisper.cpp language code, e.g. "jw" -> "Javanese" in+ * an English UI, "japonais" in a French one. Falls back to whisper's own+ * English name (`ENGLISH_NAMES`) when the active locale's ICU data can't+ * resolve one — `Intl.DisplayNames` echoes the input code back rather than+ * throwing when it doesn't recognize it.+ *+ * `code` is typed loosely (not `WhisperLanguageCode`): `AxcutTranscript.language`+ * is `z.string().min(1)`, not validated against the known code list, so a+ * detected-language pill can hand this any non-empty string. Falls back to+ * the raw code itself — never `undefined` — when neither ICU nor+ * `ENGLISH_NAMES` recognizes it.+ */+export function languageLabel(code: string, locale: string): string {+ try {+ const resolved = displayNamesFor(locale)?.of(code);+ if (resolved && resolved.toLowerCase() !== code.toLowerCase()) return resolved;+ } catch {+ // Malformed/unsupported subtag for this Intl implementation.+ }+ return ENGLISH_NAMES[code as WhisperLanguageCode] ?? code;+}++export interface LanguageOption {+ code: TranscriptLanguageCode;+ label: string;+}++/**+ * Every language option for a "Regenerate as" picker: "auto" pinned first+ * with the caller's own translated label for it, the rest sorted by+ * localized name so a 100-language list is scannable instead of ordered by+ * whisper's internal language id.+ */+export function sortedLanguageOptions(locale: string, autoLabel: string): LanguageOption[] {+ let compare: (a: string, b: string) => number;+ try {+ compare = new Intl.Collator(locale).compare;+ } catch {+ compare = (a, b) => a.localeCompare(b);+ }+ // TRANSCRIPT_LANGUAGE_CODES always starts with "auto" (see its own comment).+ const rest = (TRANSCRIPT_LANGUAGE_CODES.slice(1) as WhisperLanguageCode[])+ .map((code) => ({ code, label: languageLabel(code, locale) }))+ .sort((a, b) => compare(a.label, b.label));+ return [{ code: "auto", label: autoLabel }, ...rest];+}diff --git a/technical-documentation/architecture/transcription-and-captions.md b/technical-documentation/architecture/transcription-and-captions.mdindex 551aeff47..df899cda3 100644--- a/technical-documentation/architecture/transcription-and-captions.md+++ b/technical-documentation/architecture/transcription-and-captions.md@@ -636,25 +636,34 @@ it deletes data## Known gaps-- **Language selector.** The "Regenerate as" picker- (`SourceTranscriptModal` in- [`src/components/ai-edition/Modals.tsx`](../../src/components/ai-edition/Modals.tsx))- offers `"auto"` plus every language the `small` multilingual model- resolves. `TRANSCRIPT_LANGUAGE_CODES` / `TRANSCRIPT_LANGUAGE_NAMES` in+- **Language selector.** The "Regenerate as" picker offers `"auto"` plus+ every language the `small` multilingual model resolves. There are two+ copies of it in the tree — `MediaStage.tsx`'s Media stage panel+ ([`src/components/ai-edition/v4/MediaStage.tsx`](../../src/components/ai-edition/v4/MediaStage.tsx)),+ the one actually mounted by `NewEditorShell`, and `SourceTranscriptModal`+ ([`src/components/ai-edition/Modals.tsx`](../../src/components/ai-edition/Modals.tsx)),+ which is currently unreachable: `LeftPanel` (its only mount site) is only+ ever rendered with `active="chat"` by `NewEditorShell.tsx`, so the+ `MediaPane` branch that would render it never runs. Both are kept correct+ rather than deleting the unreachable one, since nothing marks it dead code+ and a future rewire could reach it. `TRANSCRIPT_LANGUAGE_CODES` in[`src/lib/ai-edition/schema/index.ts`](../../src/lib/ai-edition/schema/index.ts)- mirror whisper.cpp's own `g_lang` table verbatim — a code outside that list- fails to resolve a language id in `wparams.language`- (`electron/native/whisper-stt/src/main.cpp`) — and are the single source- the picker's options are built from, so the two cannot drift the way a- hand-duplicated list would. Option labels come from `Intl.DisplayNames` in- the active UI locale, falling back to whisper.cpp's own English name for a- code that locale's ICU data can't resolve. Forcing a language skips- detection on the first window and slightly improves WER.+ mirrors whisper.cpp's own `g_lang` table verbatim — a code outside that+ list fails to resolve a language id in `wparams.language`+ (`electron/native/whisper-stt/src/main.cpp`) — and `languageLabel` /+ `sortedLanguageOptions` in+ [`src/lib/ai-edition/transcription/languageLabels.ts`](../../src/lib/ai-edition/transcription/languageLabels.ts)+ are the single place both pickers build their options and labels from, so+ the two copies cannot drift from each other the way two hand-duplicated+ lists would. Option labels come from `Intl.DisplayNames` in the active UI+ locale, falling back to whisper.cpp's own English name for a code that+ locale's ICU data can't resolve. Forcing a language skips detection on the+ first window and slightly improves WER.Note that `"auto"` is a *request* value only. The helper used to echo therequest straight back into `detected_language`, so with no selector the fieldwas permanently the literal string `"auto"`: the media stage's "detected- language" line ([`src/components/ai-edition/Modals.tsx:1891`](../../src/components/ai-edition/Modals.tsx:1891))+ language" line ([`src/components/ai-edition/v4/MediaStage.tsx:347`](../../src/components/ai-edition/v4/MediaStage.tsx:347))displayed 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.