From 7b459af47cfdaa7f2cf3881220d186f9b66d9e3c Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 2 Nov 2026 21:28:16 +0100 Subject: [PATCH 1/2] fix(mobile): transcribe voice input in the device language Voice input passed the Intl locale to Apple's transcriber. Hermes derives it from NSLocale.currentLocale, which follows the app's localizations. The app ships English only, so a device set to Korean or German reported en_KR or en_CH and Apple transcribed the speech as English words. Read the device's language list (AppleLanguages) instead and fall back to the Intl locale only when it is empty. Fixes #12743 Co-Authored-By: Claude Opus 5.5 --- .../mobile/src/lib/voiceInputLanguage.test.ts | 23 +++++++++++++++++++ apps/mobile/src/lib/voiceInputLanguage.ts | 14 +++++++++++ apps/mobile/src/native/deviceLanguages.ts | 15 ++++++++++++ .../src/native/voiceTranscription.ios.test.ts | 14 +++++++++++ .../src/native/voiceTranscription.ios.ts | 8 ++++++- docs/user/composer.md | 4 ++++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 apps/mobile/src/lib/voiceInputLanguage.test.ts create mode 100644 apps/mobile/src/lib/voiceInputLanguage.ts create mode 100644 apps/mobile/src/native/deviceLanguages.ts diff --git a/apps/mobile/src/lib/voiceInputLanguage.test.ts b/apps/mobile/src/lib/voiceInputLanguage.test.ts new file mode 100644 index 0000000000000..da336f80aa14d --- /dev/null +++ b/apps/mobile/src/lib/voiceInputLanguage.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { normalizeLanguages, resolveVoiceInputLanguage } from "./voiceInputLanguage"; + +describe("normalizeLanguages", () => { + it("keeps string tags in order without duplicates", () => { + expect(normalizeLanguages(["de-CH", "en-CH", 4, "", "de-CH"])).toEqual(["de-CH", "en-CH"]); + }); + + it("returns nothing for a missing value", () => { + expect(normalizeLanguages(undefined)).toEqual([]); + }); +}); + +describe("resolveVoiceInputLanguage", () => { + it("follows the device's first language rather than the app locale", () => { + expect(resolveVoiceInputLanguage(["ko-KR", "en-KR"], "en-KR")).toBe("ko-KR"); + }); + + it("falls back to the app locale without a language list", () => { + expect(resolveVoiceInputLanguage([], "en-US")).toBe("en-US"); + }); +}); diff --git a/apps/mobile/src/lib/voiceInputLanguage.ts b/apps/mobile/src/lib/voiceInputLanguage.ts new file mode 100644 index 0000000000000..da6ab56ad939b --- /dev/null +++ b/apps/mobile/src/lib/voiceInputLanguage.ts @@ -0,0 +1,14 @@ +export function normalizeLanguages(value: unknown): ReadonlyArray { + if (!Array.isArray(value)) return []; + return [ + ...new Set(value.filter((tag): tag is string => typeof tag === "string" && tag.length > 0)), + ]; +} + +/** The device's first language, or the app locale when the device reports none. */ +export function resolveVoiceInputLanguage( + languages: ReadonlyArray, + fallback: string, +): string { + return languages[0] ?? fallback; +} diff --git a/apps/mobile/src/native/deviceLanguages.ts b/apps/mobile/src/native/deviceLanguages.ts new file mode 100644 index 0000000000000..93d1ca4b6cbc3 --- /dev/null +++ b/apps/mobile/src/native/deviceLanguages.ts @@ -0,0 +1,15 @@ +import { Platform, Settings } from "react-native"; + +import { normalizeLanguages } from "../lib/voiceInputLanguage"; + +/** + * The languages from the device's language list, most preferred first. + * + * `Intl` cannot answer this: Hermes takes its default locale from `NSLocale.currentLocale`, which + * follows the app's own localizations. The app ships English only, so a device set to German + * still reports an English locale there. + */ +export function deviceLanguages(): ReadonlyArray { + if (Platform.OS !== "ios") return []; + return normalizeLanguages(Settings.get("AppleLanguages")); +} diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index d3ee19c262de6..f4bc666638cd4 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -8,8 +8,11 @@ const mocks = vi.hoisted(() => ({ prepare: vi.fn<(locale: string) => Promise>(), transcribe: vi.fn<(audio: ArrayBufferLike, locale: string) => Promise>(), readAudio: vi.fn<() => Promise>(), + deviceLanguages: vi.fn<() => ReadonlyArray>(), })); +vi.mock("./deviceLanguages", () => ({ deviceLanguages: mocks.deviceLanguages })); + vi.mock("@react-native-ai/apple/src/NativeAppleTranscription", () => ({ default: { isAvailable: mocks.isAvailable, @@ -49,6 +52,7 @@ beforeEach(() => { mocks.prepare.mockResolvedValue("sv-SE"); mocks.readAudio.mockResolvedValue(audio); mocks.transcribe.mockResolvedValue(nativeTranscript); + mocks.deviceLanguages.mockReturnValue(["sv-SE", "en-GB"]); }); afterEach(() => { @@ -79,4 +83,14 @@ describe("getLocalVoiceTranscriber", () => { expect(error).toMatchObject({ code: "cancelled" }); expect(mocks.transcribe).not.toHaveBeenCalled(); }); + + it("transcribes in the device's first language", async () => { + const options = { signal: new AbortController().signal }; + const prepared = await getLocalVoiceTranscriber()!.prepare(options); + await prepared.transcribe("file:///voice.m4a", options); + + expect(mocks.isAvailable).toHaveBeenCalledWith("sv-SE"); + expect(mocks.prepare).toHaveBeenCalledWith("sv-SE"); + expect(mocks.transcribe).toHaveBeenCalledWith(audio, "sv-SE"); + }); }); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index 216b9e958dd66..01bc9aab49074 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -9,8 +9,14 @@ import { type VoiceTranscriptionOptions, } from "@t3tools/client-runtime/voice-input"; +import { resolveVoiceInputLanguage } from "../lib/voiceInputLanguage"; +import { deviceLanguages } from "./deviceLanguages"; + function getDeviceLocale(): string { - return Intl.DateTimeFormat().resolvedOptions().locale; + return resolveVoiceInputLanguage( + deviceLanguages(), + Intl.DateTimeFormat().resolvedOptions().locale, + ); } function wrapError( diff --git a/docs/user/composer.md b/docs/user/composer.md index a3e06c9aed6f7..01e7b935a76fe 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -200,6 +200,10 @@ 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. +Voice input transcribes in the first language of your iPhone's language list +(**Settings → General → Language & Region**). Apple transcribes one language per +recording and does not detect it. + 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 af2cd0481a947b4b383abfe4cc09b56935f502d7 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 4 Nov 2026 07:56:27 +0000 Subject: [PATCH 2/2] fix(mobile): await voice transcriber in device language test --- apps/mobile/src/native/voiceTranscription.ios.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index e00e2b94cd3e4..c5a113c232abb 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -86,7 +86,7 @@ describe("getLocalVoiceTranscriber", () => { it("transcribes in the device's first language", async () => { const options = { signal: new AbortController().signal }; - const prepared = await getLocalVoiceTranscriber()!.prepare(options); + const prepared = await (await getLocalVoiceTranscriber())!.prepare(options); await prepared.transcribe("file:///voice.m4a", options); expect(mocks.isAvailable).toHaveBeenCalledWith("sv-SE");