From 0438ff29f732632fe5ba8437aa01f17f2995c383 Mon Sep 17 00:00:00 2001 From: Joaquim Peres Date: Mon, 2 Nov 2026 18:17:19 -0400 Subject: [PATCH 1/5] feat(mobile): choose the dictation language for voice input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voice input always transcribed in the app's locale, and the app ships only in English, so other spoken languages came out as English. Add a Dictation language choice under Settings → Microphone. Unset keeps following the device language. Co-authored-by: Gabriel Schmitt --- .../SettingsMicrophoneRouteScreen.tsx | 26 +++++++++++++++ .../src/features/settings/settings-search.ts | 2 +- .../voice-input/VoiceInputProvider.tsx | 9 +++++- apps/mobile/src/lib/dictationLanguage.ts | 32 +++++++++++++++++++ .../src/native/voiceTranscription.ios.test.ts | 12 +++++++ .../src/native/voiceTranscription.ios.ts | 6 ++-- apps/mobile/src/native/voiceTranscription.ts | 2 +- .../src/persistence/mobile-preferences.ts | 7 ++++ docs/user/composer.md | 3 ++ 9 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 apps/mobile/src/lib/dictationLanguage.ts diff --git a/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx index 480ae40232e39..d1acecc4e467f 100644 --- a/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx @@ -10,6 +10,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context"; import { type AppSymbolName } from "../../components/ui/AppSymbol"; import { AppText as Text } from "../../components/ui/AppText"; import { cn } from "../../lib/cn"; +import { DICTATION_LANGUAGES } from "../../lib/dictationLanguage"; import { makePermissionStatusAtom } from "../../lib/permissionStatusAtom"; import { isMicrophoneDevice, @@ -23,6 +24,7 @@ import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/ import { ListRowLayout } from "../../components/ui/ListRowLayout"; import { ThreadSwipeable } from "../home/thread-swipe-actions"; import { ListActionRow as SettingsActionRow } from "../../components/ui/ListActionRow"; +import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow"; import { SettingsDragHandle } from "./components/SettingsDragHandle"; import { SettingsSection } from "./components/SettingsSection"; @@ -126,6 +128,9 @@ function MicrophoneSettings() { const entries = microphoneOrder( AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value.microphones : undefined, ); + const dictationLocale = AsyncResult.isSuccess(preferencesResult) + ? (preferencesResult.value.dictationLocale ?? null) + : null; const { permission, request: requestPermission } = useMicrophonePermission(); const [drag, setDrag] = useState<{ readonly key: string; readonly translation: number } | null>( null, @@ -231,6 +236,27 @@ function MicrophoneSettings() { devices are added by name after you use voice input with them connected; until then, the Other row ranks them. Swipe a device left to forget it. + + savePreferences({ dictationLocale: null })} + /> + {DICTATION_LANGUAGES.map((language) => ( + savePreferences({ dictationLocale: language.locale })} + /> + ))} + + + Voice input transcribes on this device. The first use of a language downloads it. + ); diff --git a/apps/mobile/src/features/settings/settings-search.ts b/apps/mobile/src/features/settings/settings-search.ts index c11a89a7c3a10..cd85623909add 100644 --- a/apps/mobile/src/features/settings/settings-search.ts +++ b/apps/mobile/src/features/settings/settings-search.ts @@ -29,7 +29,7 @@ const SETTINGS_SEARCH_TERMS = { ], SettingsNavigation: ["tabs", "tab order", "reorder", "hide tabs"], SettingsKeyboard: ["return key", "send message", "new line", "hardware keyboard"], - SettingsMicrophone: ["voice", "dictation", "audio input", "bluetooth"], + SettingsMicrophone: ["voice", "dictation", "audio input", "bluetooth", "language"], SettingsScheduledTasks: ["automations", "schedule", "cron", "recurring", "webhook"], SettingsProjectOverview: ["project", "overview", "checkouts", "delete project"], SettingsOrganization: [ diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index 809ee3a9d21b5..79edec6d50016 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -91,7 +91,14 @@ const voiceInputAtom = Atom.make((get) => { }); const session: VoiceInputSession = new VoiceInputSession({ recorder, - getTranscriber: getLocalVoiceTranscriber, + getTranscriber: () => { + const preferences = registry.get(mobilePreferencesAtom); + return getLocalVoiceTranscriber( + AsyncResult.isSuccess(preferences) + ? (preferences.value.dictationLocale ?? undefined) + : undefined, + ); + }, requestPermission: async () => { const permission = await requestRecordingPermissionsAsync(); return { granted: permission.granted, canAskAgain: permission.canAskAgain }; diff --git a/apps/mobile/src/lib/dictationLanguage.ts b/apps/mobile/src/lib/dictationLanguage.ts new file mode 100644 index 0000000000000..3d90c67c734ca --- /dev/null +++ b/apps/mobile/src/lib/dictationLanguage.ts @@ -0,0 +1,32 @@ +/** Locales Apple's on-device SpeechTranscriber offers. Unset follows the device language. */ +export const DICTATION_LANGUAGES = [ + { locale: "en-US", label: "English (US)" }, + { locale: "en-GB", label: "English (UK)" }, + { locale: "en-AU", label: "English (Australia)" }, + { locale: "en-CA", label: "English (Canada)" }, + { locale: "en-IN", label: "English (India)" }, + { locale: "pt-BR", label: "Português (Brasil)" }, + { locale: "pt-PT", label: "Português (Portugal)" }, + { locale: "es-ES", label: "Español (España)" }, + { locale: "es-MX", label: "Español (México)" }, + { locale: "es-US", label: "Español (EE. UU.)" }, + { locale: "fr-FR", label: "Français (France)" }, + { locale: "fr-CA", label: "Français (Canada)" }, + { locale: "de-DE", label: "Deutsch" }, + { locale: "it-IT", label: "Italiano" }, + { locale: "ja-JP", label: "日本語" }, + { locale: "ko-KR", label: "한국어" }, + { locale: "zh-CN", label: "中文(普通话)" }, + { locale: "zh-TW", label: "中文(台灣)" }, + { locale: "yue-CN", label: "粵語" }, +] as const; + +export type DictationLocale = (typeof DICTATION_LANGUAGES)[number]["locale"]; + +const DICTATION_LOCALES: ReadonlySet = new Set( + DICTATION_LANGUAGES.map((language) => language.locale), +); + +export function isDictationLocale(value: unknown): value is DictationLocale { + return typeof value === "string" && DICTATION_LOCALES.has(value); +} diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index d3ee19c262de6..69702e31240c6 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -79,4 +79,16 @@ describe("getLocalVoiceTranscriber", () => { expect(error).toMatchObject({ code: "cancelled" }); expect(mocks.transcribe).not.toHaveBeenCalled(); }); + + it("prepares and transcribes the preferred locale instead of the device locale", async () => { + mocks.prepare.mockResolvedValue("pt-BR"); + const options = { signal: new AbortController().signal }; + const prepared = await getLocalVoiceTranscriber("pt-BR")!.prepare(options); + await prepared.transcribe("file:///voice.m4a", options); + + expect(mocks.isAvailable).toHaveBeenCalledWith("pt-BR"); + expect(mocks.prepare).toHaveBeenCalledWith("pt-BR"); + expect(mocks.transcribe).toHaveBeenCalledWith(audio, "pt-BR"); + expect(prepared.locale).toBe("pt-BR"); + }); }); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index 216b9e958dd66..6177b1bd2a2a8 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -33,8 +33,8 @@ function getNativeErrorCode(error: unknown): string | undefined { return typeof error.code === "string" ? error.code : undefined; } -export function getLocalVoiceTranscriber(): VoiceTranscriber | null { - const locale = getDeviceLocale(); +export function getLocalVoiceTranscriber(preferredLocale?: string): VoiceTranscriber | null { + const locale = preferredLocale ?? getDeviceLocale(); if (!AppleTranscription.isAvailable(locale)) return null; return { prepare: (options) => prepareVoiceTranscription(locale, options) }; } @@ -63,7 +63,7 @@ async function prepareVoiceTranscription( if (getNativeErrorCode(error) === "AppleTranscriptionUnsupportedLocale") { throw new VoiceTranscriptionError( "unsupported-locale", - "Voice transcription does not support this device language.", + "Voice transcription does not support this language.", { cause: error }, ); } diff --git a/apps/mobile/src/native/voiceTranscription.ts b/apps/mobile/src/native/voiceTranscription.ts index e003064ae3f84..8008a2d9ac522 100644 --- a/apps/mobile/src/native/voiceTranscription.ts +++ b/apps/mobile/src/native/voiceTranscription.ts @@ -1,5 +1,5 @@ import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; -export function getLocalVoiceTranscriber(): VoiceTranscriber | null { +export function getLocalVoiceTranscriber(_preferredLocale?: string): VoiceTranscriber | null { return null; } diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 43ac75e185411..c002794a5b554 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -16,6 +16,7 @@ import { } from "@t3tools/contracts"; import type { AndroidNavigationStyle } from "../lib/androidNavigationStyle"; import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior"; +import { isDictationLocale, type DictationLocale } from "../lib/dictationLanguage"; import type { FollowUpBehavior } from "../lib/followUpBehavior"; import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority"; import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme"; @@ -112,6 +113,8 @@ export interface Preferences { readonly composerEnterBehavior?: ComposerEnterBehavior; readonly followUpBehavior?: FollowUpBehavior; readonly microphones?: ReadonlyArray; + /** Unset or null means dictation follows the device language. */ + readonly dictationLocale?: DictationLocale | null; readonly projectGroupingEnabled?: boolean; readonly projectGroupingMode?: SidebarProjectGroupingMode; readonly planModeEnabled?: boolean; @@ -192,6 +195,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { composerEnterBehavior?: ComposerEnterBehavior; followUpBehavior?: FollowUpBehavior; microphones?: ReadonlyArray; + dictationLocale?: DictationLocale | null; projectGroupingEnabled?: boolean; projectGroupingMode?: SidebarProjectGroupingMode; planModeEnabled?: boolean; @@ -308,6 +312,9 @@ function sanitizePreferences(parsed: Preferences): Preferences { : []; }); } + if (parsed.dictationLocale === null || isDictationLocale(parsed.dictationLocale)) { + preferences.dictationLocale = parsed.dictationLocale; + } if (typeof parsed.projectGroupingEnabled === "boolean") { preferences.projectGroupingEnabled = parsed.projectGroupingEnabled; } diff --git a/docs/user/composer.md b/docs/user/composer.md index a3e06c9aed6f7..0e1f070f642c5 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -200,6 +200,9 @@ for example, put **Other Bluetooth** above your AirPods so a new headset is pref while the AirPods microphone stays low. By default, CarPlay comes after the built-in microphone. Swipe a device left to forget it. +To choose the language voice input transcribes, such as Brazilian Portuguese, pick it +under **Settings → Microphone → Dictation language**. **Device language** is the default. + Transcription runs on your device. T3 Code deletes the temporary audio after transcription or cancellation; only the message text is sent when you submit. From 1a7e852b190af0979bb7462f6836b5717c0a2f96 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Thu, 5 Nov 2026 07:54:13 +0000 Subject: [PATCH 2/5] fix(mobile): wait for saved dictation language before starting voice input --- apps/mobile/src/features/voice-input/VoiceInputProvider.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index da5259b03cefd..7104841ef0142 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -121,6 +121,7 @@ const voiceInputAtom = Atom.make((get) => { const transcriber = registry.get(localVoiceTranscriberAtom); if (transcriber === "checking" || transcriber === null) return null; const preferences = registry.get(mobilePreferencesAtom); + if (AsyncResult.isInitial(preferences)) return null; const locale = AsyncResult.isSuccess(preferences) ? preferences.value.dictationLocale : undefined; From 80cfc2b25b511edd6d2304401a3d7f38a6b1a0db Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 6 Nov 2026 08:48:25 +0000 Subject: [PATCH 3/5] test(mobile): expect a chosen locale's unsupported error at transcription --- apps/mobile/src/native/voiceTranscription.ios.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index 9dead6aa0c910..e6fa6ef24cf66 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -276,13 +276,13 @@ describe("getLocalVoiceTranscriber", () => { }); it("fails on a chosen locale the device cannot transcribe instead of falling back", async () => { - mocks.prepare.mockRejectedValue( - Object.assign(new Error("unsupported"), { code: "AppleTranscriptionUnsupportedLocale" }), - ); + useLanguages(["en-US"], "en-US"); + mocks.prepare.mockRejectedValue(unsupportedLocale()); const options = { signal: new AbortController().signal }; const error = await getVoiceTranscriberForLocale("de-DE")! .prepare(options) + .then((prepared) => prepared.transcribe("file:///voice.m4a", options)) .catch((error: unknown) => error); expect(error).toBeInstanceOf(VoiceTranscriptionError); From e83a7a3a6b083bf9c54a6f80e0d4a8ab45dddf13 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 18 Nov 2026 09:35:39 +0000 Subject: [PATCH 4/5] fix(mobile): preserve native dictation language names --- apps/mobile/src/lib/dictationLanguage.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/mobile/src/lib/dictationLanguage.ts b/apps/mobile/src/lib/dictationLanguage.ts index 3d90c67c734ca..8967c05acb4b3 100644 --- a/apps/mobile/src/lib/dictationLanguage.ts +++ b/apps/mobile/src/lib/dictationLanguage.ts @@ -1,4 +1,5 @@ /** Locales Apple's on-device SpeechTranscriber offers. Unset follows the device language. */ +/* oxlint-disable t3code/no-untranslated-copy -- Language names stay in their native languages in every locale. */ export const DICTATION_LANGUAGES = [ { locale: "en-US", label: "English (US)" }, { locale: "en-GB", label: "English (UK)" }, @@ -20,6 +21,7 @@ export const DICTATION_LANGUAGES = [ { locale: "zh-TW", label: "中文(台灣)" }, { locale: "yue-CN", label: "粵語" }, ] as const; +/* oxlint-enable t3code/no-untranslated-copy */ export type DictationLocale = (typeof DICTATION_LANGUAGES)[number]["locale"]; From 305396bb347430b450d348206499b34ca7a21528 Mon Sep 17 00:00:00 2001 From: Joaquim Peres Date: Fri, 20 Nov 2026 09:54:23 -0400 Subject: [PATCH 5/5] fix(mobile): address dictation language review findings - Hide the Dictation language section while an environment's cloud sheet is open. - Wait for saved preferences instead of reporting dictation unavailable during startup. - Choose the unsupported-language message by selection mode, not candidate count. - Assert the chosen-locale error comes from transcription, not preparation. --- .../settings/SettingsVoiceRouteScreen.tsx | 2 +- .../voice-input/VoiceInputProvider.tsx | 45 ++++++++++++++++--- .../src/native/voiceTranscription.ios.test.ts | 24 ++++++++-- .../src/native/voiceTranscription.ios.ts | 24 +++++----- 4 files changed, 76 insertions(+), 19 deletions(-) diff --git a/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx index e58b971ae38b0..cce37c6bd8e1e 100644 --- a/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx @@ -409,7 +409,7 @@ export function SettingsVoiceRouteScreen() { )} {/* Google's on-device recognizer on Android always uses the device language. */} - {Platform.OS === "ios" && !grant ? ( + {Platform.OS === "ios" && !grant && !sheetEnvironment ? ( <> void { export const deviceMicrophoneOrder = (saved?: ReadonlyArray) => microphoneOrder(saved, Platform.OS === "android" ? "android" : "ios"); +type MobilePreferencesResult = Atom.Type; + +/** A chosen dictation language replaces the device language; a failed preference load keeps it. */ +function withDictationLocale( + transcriber: VoiceTranscriber, + preferences: MobilePreferencesResult, +): VoiceTranscriber { + const locale = AsyncResult.isSuccess(preferences) ? preferences.value.dictationLocale : undefined; + return (locale ? getVoiceTranscriberForLocale(locale) : null) ?? transcriber; +} + /** "checking" until the first availability probe settles; re-probed on foreground. */ export const localVoiceTranscriberAtom = makePermissionStatusAtom< VoiceTranscriber | null | "checking" @@ -129,11 +141,34 @@ const voiceInputAtom = Atom.make((get) => { const transcriber = registry.get(localVoiceTranscriberAtom); if (transcriber === "checking" || transcriber === null) return null; const preferences = registry.get(mobilePreferencesAtom); - if (AsyncResult.isInitial(preferences)) return null; - const locale = AsyncResult.isSuccess(preferences) - ? preferences.value.dictationLocale - : undefined; - return (locale ? getVoiceTranscriberForLocale(locale) : null) ?? transcriber; + if (!AsyncResult.isInitial(preferences)) return withDictationLocale(transcriber, preferences); + // Saved preferences are still loading: start now and pick the language once they arrive, + // so a tap during startup neither reports dictation unavailable nor uses the wrong language. + return { + prepare: async (options) => { + throwIfVoiceTranscriptionAborted(options.signal); + const loaded = await new Promise((resolve) => { + const settle = (result: MobilePreferencesResult) => { + if (AsyncResult.isInitial(result)) return; + stop(); + resolve(result); + }; + const abort = () => { + stop(); + resolve(null); + }; + const unsubscribe = registry.subscribe(mobilePreferencesAtom, settle); + const stop = () => { + unsubscribe(); + options.signal.removeEventListener("abort", abort); + }; + options.signal.addEventListener("abort", abort, { once: true }); + settle(registry.get(mobilePreferencesAtom)); + }); + throwIfVoiceTranscriptionAborted(options.signal); + return withDictationLocale(transcriber, loaded!).prepare(options); + }, + }; }, requestPermission: permission.requestPermission, configureRecording: async () => { diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index e6fa6ef24cf66..91f8968c5b9ab 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -264,6 +264,23 @@ describe("getLocalVoiceTranscriber", () => { expect(mocks.transcribe).not.toHaveBeenCalled(); }); + it("keeps the device-language message when the device offers a single language", async () => { + useLanguages(["en-US"], "en-US"); + mocks.prepare.mockRejectedValue(unsupportedLocale()); + const options = { signal: new AbortController().signal }; + + const prepared = await (await getLocalVoiceTranscriber())!.prepare(options); + const error = await prepared + .transcribe("file:///voice.m4a", options) + .catch((error: unknown) => error); + + expect(error).toMatchObject({ + code: "unsupported-locale", + message: "Voice transcription does not support any of your languages.", + }); + expect(mocks.prepare).toHaveBeenCalledTimes(1); + }); + it("prepares and transcribes a chosen locale instead of the device locale", async () => { mocks.prepare.mockResolvedValue("pt-BR"); const options = { signal: new AbortController().signal }; @@ -280,9 +297,10 @@ describe("getLocalVoiceTranscriber", () => { mocks.prepare.mockRejectedValue(unsupportedLocale()); const options = { signal: new AbortController().signal }; - const error = await getVoiceTranscriberForLocale("de-DE")! - .prepare(options) - .then((prepared) => prepared.transcribe("file:///voice.m4a", options)) + // Preparation hands back a handle so recording can start; the unsupported model fails at transcription. + const prepared = await getVoiceTranscriberForLocale("de-DE")!.prepare(options); + const error = await prepared + .transcribe("file:///voice.m4a", options) .catch((error: unknown) => error); expect(error).toBeInstanceOf(VoiceTranscriptionError); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index 5f4e1da08c675..ab977329b9dfc 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -50,16 +50,17 @@ export async function getLocalVoiceTranscriber(): Promise prepareVoiceTranscription(locales, options) }; + return { prepare: (options) => prepareVoiceTranscription(locales, false, options) }; } /** A chosen language stays fixed: one the device can't transcribe fails instead of falling back. */ export function getVoiceTranscriberForLocale(locale: string): VoiceTranscriber | null { - return { prepare: (options) => prepareVoiceTranscription([locale], options) }; + return { prepare: (options) => prepareVoiceTranscription([locale], true, options) }; } async function prepareVoiceTranscription( locales: readonly string[], + chosen: boolean, { signal }: VoiceTranscriptionOptions, ): Promise { throwIfVoiceTranscriptionAborted(signal); @@ -75,7 +76,7 @@ async function prepareVoiceTranscription( } let locale = locales[0]!; - const model = prepareLocales(locales, signal).then((supported) => { + const model = prepareLocales(locales, chosen, signal).then((supported) => { locale = supported; }); // Recorder setup can fail before either consumer observes the model. @@ -107,12 +108,16 @@ async function prepareVoiceTranscription( }; } -async function prepareLocales(locales: readonly string[], signal: AbortSignal): Promise { +async function prepareLocales( + locales: readonly string[], + chosen: boolean, + signal: AbortSignal, +): Promise { throwIfVoiceTranscriptionAborted(signal); let unsupported: VoiceTranscriptionError | undefined; for (const locale of locales) { try { - return await prepareLocale(locale, locales, signal); + return await prepareLocale(locale, chosen, signal); } catch (error) { if (!isVoiceTranscriptionError(error) || error.code !== "unsupported-locale") throw error; unsupported = error; @@ -123,7 +128,7 @@ async function prepareLocales(locales: readonly string[], signal: AbortSignal): async function prepareLocale( locale: string, - locales: readonly string[], + chosen: boolean, signal: AbortSignal, ): Promise { try { @@ -135,10 +140,9 @@ async function prepareLocale( if (getNativeErrorCode(error) === "AppleTranscriptionUnsupportedLocale") { throw new VoiceTranscriptionError({ code: "unsupported-locale", - message: - locales.length === 1 - ? m(msg("Voice transcription does not support this language.")) - : m(msg("Voice transcription does not support any of your languages.")), + message: chosen + ? m(msg("Voice transcription does not support this language.")) + : m(msg("Voice transcription does not support any of your languages.")), cause: error, }); }