Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(speech): move the language list to shared and widen it to whisper's full set
enes29c1a8f517f1
diff --git a/src/shared/speech.test.ts b/src/shared/speech.test.tsindex 60d8562d0..63dde9694 100644--- a/src/shared/speech.test.ts+++ b/src/shared/speech.test.ts@@ -7,7 +7,13 @@ import {modelAfterDownload,modelAfterDelete,SPEECH_MODEL_NONE,- type ModelDownloadState+ type ModelDownloadState,+ SPEECH_LANGUAGES,+ SPEECH_LANGUAGE_AUTO,+ speechLanguage,+ speechLanguageLabel,+ filterSpeechLanguages,+ modelKnowsV3Languages} from './speech'import { DEFAULT_SETTINGS } from './types'@@ -92,3 +98,80 @@ describe('modelAfterDelete', () => {expect(modelAfterDelete(list(['tiny', true], ['small', true]), SPEECH_MODEL_NONE)).toBeNull()})})++describe('speech language catalog', () => {+ it('covers whisper’s own language set, Polish and the rest included', () => {+ // The 7-entry hand-written list this replaced (issue #586) is the floor, not the shape:+ // every code whisper accepts must be reachable from the picker.+ const codes = SPEECH_LANGUAGES.map((l) => l.code)+ expect(codes).toHaveLength(100)+ expect(new Set(codes).size).toBe(100)+ for (const c of ['pl', 'it', 'pt', 'ru', 'uk', 'nl', 'zh', 'ko', 'hi', 'cs']) {+ expect(codes).toContain(c)+ }+ // The codes the old list had must all still be there — nobody loses their setting.+ for (const c of ['en', 'tr', 'de', 'fr', 'es', 'ja']) expect(codes).toContain(c)+ // `auto` is NOT a whisper language: it means "no hint", and lives outside the table.+ expect(codes).not.toContain(SPEECH_LANGUAGE_AUTO)+ })++ it('is ordered by English name and fully populated', () => {+ const labels = SPEECH_LANGUAGES.map((l) => l.label)+ expect(labels).toEqual([...labels].sort((a, b) => a.localeCompare(b, 'en')))+ for (const l of SPEECH_LANGUAGES) {+ expect(l.code).toMatch(/^[a-z]{2,3}$/)+ expect(l.label.length).toBeGreaterThan(0)+ expect(l.endonym.length).toBeGreaterThan(0)+ // An alias that only repeats the label costs a scan and teaches nothing.+ for (const a of l.aliases ?? []) expect(a.toLowerCase()).not.toBe(l.label.toLowerCase())+ }+ })++ it('marks Cantonese as the one large-v3-only entry', () => {+ expect(SPEECH_LANGUAGES.filter((l) => l.sinceV3).map((l) => l.code)).toEqual(['yue'])+ expect(modelKnowsV3Languages('large-v3-turbo')).toBe(true)+ expect(modelKnowsV3Languages('tiny')).toBe(false)+ expect(modelKnowsV3Languages('small')).toBe(false)+ })++ it('names the stored value, and hands back an unknown code instead of eating it', () => {+ expect(speechLanguageLabel('auto')).toBe('Auto-detect')+ expect(speechLanguageLabel('pl')).toBe('Polish')+ // The old <select> rendered a stored code it did not know as blank and overwrote it on the+ // next click. A code we cannot name is still the user's setting.+ expect(speechLanguageLabel('xx')).toBe('xx')+ expect(speechLanguageLabel('')).toBe('')+ expect(speechLanguage('pl')).toMatchObject({ label: 'Polish', endonym: 'polski' })+ expect(speechLanguage('xx')).toBeUndefined()+ })++ it('finds a language by code, English name, endonym or alias', () => {+ const first = (q: string): string | undefined => filterSpeechLanguages(q)[0]?.code+ expect(first('pl')).toBe('pl')+ expect(first('pol')).toBe('pl')+ expect(first('polski')).toBe('pl')+ expect(first('Polish')).toBe('pl')+ expect(first('deutsch')).toBe('de')+ expect(first('mandarin')).toBe('zh') // whisper's own alias table+ expect(first('bengali')).toBe('bn') // CLDR calls it Bangla+ expect(filterSpeechLanguages('zzzz')).toEqual([])+ expect(filterSpeechLanguages(' ')).toEqual(SPEECH_LANGUAGES)+ })++ it('folds diacritics, so a speaker can type their own name without them', () => {+ const first = (q: string): string | undefined => filterSpeechLanguages(q)[0]?.code+ expect(first('turkce')).toBe('tr') // Türkçe+ expect(first('cestina')).toBe('cs') // čeština+ expect(first('islenska')).toBe('is') // íslenska+ // Non-Latin scripts are searched as typed.+ expect(first('русский')).toBe('ru')+ expect(first('日本語')).toBe('ja')+ })++ it('ranks an exact code above a name that merely contains it', () => {+ // "pl" is a substring of Nepali's endonym neighbourhood; the code must still win.+ expect(filterSpeechLanguages('pl')[0].code).toBe('pl')+ // Prefix beats substring: "ka" is Georgian's code, and also inside "Slovak"/"Kazakh".+ expect(filterSpeechLanguages('ka')[0].code).toBe('ka')+ })+})diff --git a/src/shared/speech.ts b/src/shared/speech.tsindex 0eaa1b931..06f365a33 100644--- a/src/shared/speech.ts+++ b/src/shared/speech.ts@@ -16,6 +16,196 @@ export const WHISPER_MODELS: WhisperModelInfo[] = [export const WHISPER_DOWNLOAD_BASE = 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/'+/**+ * A language whisper can be pinned to. `code` is whisper's OWN code and is what goes on the wire+ * unchanged — for local whisper.cpp and for the cloud `locale` alike.+ *+ * `label` is CLDR's English name and `endonym` the language's name in itself, because the person+ * who needs Polish types "polski" at least as often as "Polish"; `aliases` carries the spellings+ * neither covers — whisper's own English name where it differs from CLDR's ("Myanmar" for Burmese),+ * plus whisper's documented alias table ("Valencian", "Castilian", "Mandarin", …). All three are+ * searched, so no entry is reachable only by knowing the code.+ *+ * The set is whisper's `LANGUAGES` table (tokenizer.py) verbatim, so it is exactly what the+ * engine accepts — no more (an unknown code makes whisper.cpp fail the transcription) and no+ * less (the 7-entry hand-written list this replaced was the ONLY thing standing between a Polish+ * speaker and working dictation; nothing below the dropdown ever validated the code).+ */+export interface SpeechLanguage {+ code: string+ label: string+ endonym: string+ aliases?: string[]+ /** Cantonese exists only from large-v3 on — the earlier models have no token for it. */+ sinceV3?: true+}++/** Let whisper guess the language from the audio. Not one of whisper's codes — the engines take+ * it as "no hint", which is why it is spelled here rather than living in the table. */+export const SPEECH_LANGUAGE_AUTO = 'auto'++/** Whisper's 100 languages, ordered by English name (this is read top-to-bottom in a picker;+ * whisper's own order is by training-data volume and looks arbitrary on screen). */+export const SPEECH_LANGUAGES: readonly SpeechLanguage[] = [+ { code: 'af', label: 'Afrikaans', endonym: 'Afrikaans' },+ { code: 'sq', label: 'Albanian', endonym: 'shqip' },+ { code: 'am', label: 'Amharic', endonym: 'አማርኛ' },+ { code: 'ar', label: 'Arabic', endonym: 'العربية' },+ { code: 'hy', label: 'Armenian', endonym: 'հայերեն' },+ { code: 'as', label: 'Assamese', endonym: 'অসমীয়া' },+ { code: 'az', label: 'Azerbaijani', endonym: 'azərbaycan' },+ { code: 'bn', label: 'Bangla', endonym: 'বাংলা', aliases: ['Bengali'] },+ { code: 'ba', label: 'Bashkir', endonym: 'башҡорт' },+ { code: 'eu', label: 'Basque', endonym: 'euskara' },+ { code: 'be', label: 'Belarusian', endonym: 'беларуская' },+ { code: 'bs', label: 'Bosnian', endonym: 'bosanski' },+ { code: 'br', label: 'Breton', endonym: 'brezhoneg' },+ { code: 'bg', label: 'Bulgarian', endonym: 'български' },+ { code: 'my', label: 'Burmese', endonym: 'မြန်မာ', aliases: ['Myanmar'] },+ { code: 'yue', label: 'Cantonese', endonym: '粵語', sinceV3: true },+ { code: 'ca', label: 'Catalan', endonym: 'català', aliases: ['Valencian'] },+ { code: 'zh', label: 'Chinese', endonym: '中文', aliases: ['Mandarin'] },+ { code: 'hr', label: 'Croatian', endonym: 'hrvatski' },+ { code: 'cs', label: 'Czech', endonym: 'čeština' },+ { code: 'da', label: 'Danish', endonym: 'dansk' },+ { code: 'nl', label: 'Dutch', endonym: 'Nederlands', aliases: ['Flemish'] },+ { code: 'en', label: 'English', endonym: 'English' },+ { code: 'et', label: 'Estonian', endonym: 'eesti' },+ { code: 'fo', label: 'Faroese', endonym: 'føroyskt' },+ { code: 'tl', label: 'Filipino', endonym: 'Filipino', aliases: ['Tagalog'] },+ { code: 'fi', label: 'Finnish', endonym: 'suomi' },+ { code: 'fr', label: 'French', endonym: 'français' },+ { code: 'gl', label: 'Galician', endonym: 'galego' },+ { code: 'ka', label: 'Georgian', endonym: 'ქართული' },+ { code: 'de', label: 'German', endonym: 'Deutsch' },+ { code: 'el', label: 'Greek', endonym: 'Ελληνικά' },+ { code: 'gu', label: 'Gujarati', endonym: 'ગુજરાતી' },+ { code: 'ht', label: 'Haitian Creole', endonym: 'Haitian Creole', aliases: ['Haitian'] },+ { code: 'ha', label: 'Hausa', endonym: 'Hausa' },+ { code: 'haw', label: 'Hawaiian', endonym: 'ʻŌlelo Hawaiʻi' },+ { code: 'he', label: 'Hebrew', endonym: 'עברית' },+ { code: 'hi', label: 'Hindi', endonym: 'हिन्दी' },+ { code: 'hu', label: 'Hungarian', endonym: 'magyar' },+ { code: 'is', label: 'Icelandic', endonym: 'íslenska' },+ { code: 'id', label: 'Indonesian', endonym: 'Indonesia' },+ { code: 'it', label: 'Italian', endonym: 'italiano' },+ { code: 'ja', label: 'Japanese', endonym: '日本語' },+ { code: 'jw', label: 'Javanese', endonym: 'Jawa' },+ { code: 'kn', label: 'Kannada', endonym: 'ಕನ್ನಡ' },+ { code: 'kk', label: 'Kazakh', endonym: 'қазақ тілі' },+ { code: 'km', label: 'Khmer', endonym: 'ខ្មែរ' },+ { code: 'ko', label: 'Korean', endonym: '한국어' },+ { code: 'lo', label: 'Lao', endonym: 'ລາວ' },+ { code: 'la', label: 'Latin', endonym: 'Latin' },+ { code: 'lv', label: 'Latvian', endonym: 'latviešu' },+ { code: 'ln', label: 'Lingala', endonym: 'lingála' },+ { code: 'lt', label: 'Lithuanian', endonym: 'lietuvių' },+ { code: 'lb', label: 'Luxembourgish', endonym: 'Lëtzebuergesch', aliases: ['Letzeburgesch'] },+ { code: 'mk', label: 'Macedonian', endonym: 'македонски' },+ { code: 'mg', label: 'Malagasy', endonym: 'Malagasy' },+ { code: 'ms', label: 'Malay', endonym: 'Melayu' },+ { code: 'ml', label: 'Malayalam', endonym: 'മലയാളം' },+ { code: 'mt', label: 'Maltese', endonym: 'Malti' },+ { code: 'mi', label: 'Māori', endonym: 'Māori', aliases: ['Maori'] },+ { code: 'mr', label: 'Marathi', endonym: 'मराठी' },+ { code: 'mn', label: 'Mongolian', endonym: 'монгол' },+ { code: 'ne', label: 'Nepali', endonym: 'नेपाली' },+ { code: 'no', label: 'Norwegian', endonym: 'norsk' },+ { code: 'nn', label: 'Norwegian Nynorsk', endonym: 'norsk nynorsk', aliases: ['Nynorsk'] },+ { code: 'oc', label: 'Occitan', endonym: 'occitan' },+ { code: 'ps', label: 'Pashto', endonym: 'پښتو', aliases: ['Pushto'] },+ { code: 'fa', label: 'Persian', endonym: 'فارسی', aliases: ['Farsi'] },+ { code: 'pl', label: 'Polish', endonym: 'polski' },+ { code: 'pt', label: 'Portuguese', endonym: 'português' },+ { code: 'pa', label: 'Punjabi', endonym: 'ਪੰਜਾਬੀ', aliases: ['Panjabi'] },+ { code: 'ro', label: 'Romanian', endonym: 'română', aliases: ['Moldavian', 'Moldovan'] },+ { code: 'ru', label: 'Russian', endonym: 'русский' },+ { code: 'sa', label: 'Sanskrit', endonym: 'संस्कृत भाषा' },+ { code: 'sr', label: 'Serbian', endonym: 'српски' },+ { code: 'sn', label: 'Shona', endonym: 'chiShona' },+ { code: 'sd', label: 'Sindhi', endonym: 'سنڌي' },+ { code: 'si', label: 'Sinhala', endonym: 'සිංහල', aliases: ['Sinhalese'] },+ { code: 'sk', label: 'Slovak', endonym: 'slovenčina' },+ { code: 'sl', label: 'Slovenian', endonym: 'slovenščina' },+ { code: 'so', label: 'Somali', endonym: 'Soomaali' },+ { code: 'es', label: 'Spanish', endonym: 'español', aliases: ['Castilian'] },+ { code: 'su', label: 'Sundanese', endonym: 'Basa Sunda' },+ { code: 'sw', label: 'Swahili', endonym: 'Kiswahili' },+ { code: 'sv', label: 'Swedish', endonym: 'svenska' },+ { code: 'tg', label: 'Tajik', endonym: 'тоҷикӣ' },+ { code: 'ta', label: 'Tamil', endonym: 'தமிழ்' },+ { code: 'tt', label: 'Tatar', endonym: 'татар' },+ { code: 'te', label: 'Telugu', endonym: 'తెలుగు' },+ { code: 'th', label: 'Thai', endonym: 'ไทย' },+ { code: 'bo', label: 'Tibetan', endonym: 'བོད་སྐད་' },+ { code: 'tr', label: 'Turkish', endonym: 'Türkçe' },+ { code: 'tk', label: 'Turkmen', endonym: 'türkmen dili' },+ { code: 'uk', label: 'Ukrainian', endonym: 'українська' },+ { code: 'ur', label: 'Urdu', endonym: 'اردو' },+ { code: 'uz', label: 'Uzbek', endonym: 'o‘zbek' },+ { code: 'vi', label: 'Vietnamese', endonym: 'Tiếng Việt' },+ { code: 'cy', label: 'Welsh', endonym: 'Cymraeg' },+ { code: 'yi', label: 'Yiddish', endonym: 'ייִדיש' },+ { code: 'yo', label: 'Yoruba', endonym: 'Èdè Yorùbá' },+]++export function speechLanguage(code: string): SpeechLanguage | undefined {+ return SPEECH_LANGUAGES.find((l) => l.code === code)+}++/**+ * What to CALL the stored value. `auto` is the auto-detect row; a known code is its English name;+ * anything else is returned as-is.+ *+ * That last branch is the point: `SpeechSettings.language` is a free string with no validation+ * anywhere on the way to disk, so a hand-edited settings.json (or a build that drops an entry)+ * can hold a code this table does not know. Rendering it as the empty string is what let the old+ * `<select>` show blank and then overwrite the user's value on the next click — a display gap+ * must never become a data loss.+ */+export function speechLanguageLabel(code: string): string {+ if (code === SPEECH_LANGUAGE_AUTO) return 'Auto-detect'+ return speechLanguage(code)?.label ?? code+}++/** Whether this model's vocabulary knows every language in the table. Only the large-v3 family+ * does; see `sinceV3`. */+export function modelKnowsV3Languages(modelId: string): boolean {+ return modelId.startsWith('large-v3')+}++/** Case- and diacritic-insensitive: "turkce" finds Türkçe, "cestina" finds čeština. Non-Latin+ * scripts pass through unchanged, which is what we want — Cyrillic has nothing to strip. */+function fold(s: string): string {+ return s.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()+}++/**+ * The languages matching a picker query, best first: exact code, then names that START with the+ * query, then names that merely contain it. Ties keep the table's alphabetical order.+ *+ * The ranking is the whole reason this is not a bare `.filter()`: "pl" is a substring of "Nepali"+ * and "Napoletano"-shaped endonyms, and a Polish speaker typing their own code should not have to+ * hunt for it.+ */+export function filterSpeechLanguages(query: string): readonly SpeechLanguage[] {+ const q = fold(query.trim())+ if (q === '') return SPEECH_LANGUAGES+ const scored: { lang: SpeechLanguage; rank: number }[] = []+ for (const lang of SPEECH_LANGUAGES) {+ const names = [lang.label, lang.endonym, ...(lang.aliases ?? [])].map(fold)+ const code = lang.code.toLowerCase()+ const rank =+ code === q ? 0+ : code.startsWith(q) ? 1+ : names.some((n) => n.startsWith(q)) ? 2+ : names.some((n) => n.includes(q)) ? 3+ : -1+ if (rank >= 0) scored.push({ lang, rank })+ }+ return scored.sort((a, b) => a.rank - b.rank).map((s) => s.lang)+}+/*** The "no dictation" selection: an EMPTY model id (issue #143). A legitimate, user-chosen state —* the settings default, the onboarding "skip" choice, and the Settings → Speech "None" row all