diff --git a/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx index 6e18e2146dd92..24943b3a17d1d 100644 --- a/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx @@ -11,6 +11,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 { m } from "../../i18n/messages"; import { makePermissionStatusAtom } from "../../lib/permissionStatusAtom"; import { @@ -38,6 +39,7 @@ import type { VoiceGrant } from "../voice-input/voiceGrantStorage"; import type { EnvironmentId } from "@t3tools/contracts"; 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 { SettingsScreen } from "./components/SettingsScreen"; import { SettingsSection } from "./components/SettingsSection"; @@ -246,6 +248,9 @@ export function SettingsVoiceRouteScreen() { const entries = deviceMicrophoneOrder( 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, @@ -406,6 +411,34 @@ export function SettingsVoiceRouteScreen() { "Voice input uses the first connected microphone in this list. A wired or Bluetooth microphone is added by name the first time you dictate with it connected; until then it falls under Other. Swipe left on a named microphone to forget it.", )} + {/* Google's on-device recognizer on Android always uses the device language. */} + {Platform.OS === "ios" && !grant && !sheetEnvironment ? ( + <> + + savePreferences({ dictationLocale: null })} + /> + {DICTATION_LANGUAGES.map((language) => ( + savePreferences({ dictationLocale: language.locale })} + /> + ))} + + + {gt( + "Voice input transcribes on this device. The first use of a language downloads it.", + )} + + + ) : null} ); diff --git a/apps/mobile/src/features/settings/settings-search.ts b/apps/mobile/src/features/settings/settings-search.ts index 9b8334641290d..81cafd072289f 100644 --- a/apps/mobile/src/features/settings/settings-search.ts +++ b/apps/mobile/src/features/settings/settings-search.ts @@ -72,6 +72,7 @@ const SETTINGS_SEARCH_TERMS = { msg("preferred microphone", { $context: "settings search keyword" }), msg("microphone order", { $context: "settings search keyword" }), msg("bluetooth", { $context: "settings search keyword" }), + msg("language", { $context: "settings search keyword" }), ], SettingsScheduledTasks: [ msg("automations", { $context: "settings search keyword" }), diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index 882191260a8cd..9c1b6f8ee40b8 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -15,11 +15,15 @@ import { preferredMicrophoneInput, rememberMicrophones, } from "../../lib/microphonePriority"; -import { getLocalVoiceTranscriber } from "../../native/voiceTranscription"; +import { + getLocalVoiceTranscriber, + getVoiceTranscriberForLocale, +} from "../../native/voiceTranscription"; import { createVoiceRecorder } from "../../native/voiceRecorder"; import { mobilePreferencesAtom, saveMobilePreferences } from "../../state/preferences"; import { getNativeShowcaseScene } from "../showcase/nativeShowcaseScene"; import { + throwIfVoiceTranscriptionAborted, voiceInputBlocksSubmission, type VoiceTranscriber, } from "@t3tools/client-runtime/voice-input"; @@ -57,6 +61,17 @@ function keepScreenAwake(tag: string): () => 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" @@ -124,7 +139,36 @@ export const voiceInputAtom = Atom.make((get) => { const route = registry.get(voiceRouteAtom); if (route) return route.transcriber; const transcriber = registry.get(localVoiceTranscriberAtom); - return transcriber === "checking" ? null : transcriber; + if (transcriber === "checking" || transcriber === null) return null; + const preferences = registry.get(mobilePreferencesAtom); + 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/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index f4d80a116eece..04e64f1f4a735 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "Die Sprachtranskription konnte diese Sprache nicht vorbereiten. Prüfe {service} und versuch es erneut.", "490f22de47fe7ee8": "Sprachtranskription fehlgeschlagen.", "e29263a611de039f": "Sprachtranskription erfordert ein unterstütztes Gerät mit {platform} oder neuer.", + "324eb1b534f4dd49": "Die Sprachtranskription unterstützt diese Sprache nicht.", "111ee7a49fa0717c": "Die Sprachtranskription konnte diese Sprache nicht vorbereiten.", "69a56aab78773a39": "Die Sprachtranskription unterstützt keine deiner Sprachen.", "698777de597615cd": "Diese Verbindung kann keine Anhänge ändern.", @@ -3792,6 +3793,9 @@ "58b5dfda390dfa7c": "Bevorzugte Reihenfolge", "23ea1690c6b34f03": "Die Spracheingabe verwendet das erste verbundene Mikrofon in dieser Liste. Ein kabelgebundenes oder Bluetooth-Mikrofon wird beim ersten Diktieren mit ihm namentlich hinzugefügt; bis dahin fällt es unter „Sonstige“. Wische auf einem benannten Mikrofon nach links, um es zu vergessen. Android verwendet eventuell trotzdem ein anderes Mikrofon, wenn das bevorzugte nicht geroutet werden kann.", "ed72aea6c71f7f6d": "Die Spracheingabe verwendet das erste verbundene Mikrofon in dieser Liste. Ein kabelgebundenes oder Bluetooth-Mikrofon wird beim ersten Diktieren mit ihm namentlich hinzugefügt; bis dahin fällt es unter „Sonstige“. Wische auf einem benannten Mikrofon nach links, um es zu vergessen.", + "55d10b17c262bf53": "Diktiersprache", + "2bc9b4068b479b4f": "Gerätesprache", + "af8339c1f8150347": "Die Spracheingabe wird auf diesem Gerät transkribiert. Bei der ersten Verwendung einer Sprache wird sie heruntergeladen.", "49295375b18e1eaa": "{title}, {kind}, {position} von {count}", "ae4287de15deb58a": "Vergessen", "2595c662f9daa600": "{title} vergessen", @@ -3938,6 +3942,7 @@ "28ddc910129103ae": "bevorzugtes mikrofon", "de274992a7c156aa": "mikrofonreihenfolge", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "sprache", "02ac58b798da9931": "automatisierungen", "c4f44820c26e91c9": "zeitplan", "5ca8399aefd2acaf": "wiederkehrend", @@ -3946,7 +3951,6 @@ "b18d8b097eb4a3c2": "übersicht", "a8675ab06a18c426": "checkouts", "e44e1efba0742a8c": "projekt löschen", - "3358b338bb494339": "sprache", "a3ff3275026d0318": "gebietsschema", "bbcff924e7734cee": "übersetzung", "a67bb044f1d885bf": "englisch", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 62b182b1a30c9..6842c1841f52f 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "Voice transcription could not prepare this language. Check {service} and try again.", "490f22de47fe7ee8": "Voice transcription failed.", "e29263a611de039f": "Voice transcription requires a supported device with {platform} or later.", + "324eb1b534f4dd49": "Voice transcription does not support this language.", "111ee7a49fa0717c": "Voice transcription could not prepare this language.", "69a56aab78773a39": "Voice transcription does not support any of your languages.", "698777de597615cd": "This connection cannot change attachments.", @@ -3794,6 +3795,9 @@ "58b5dfda390dfa7c": "Preferred order", "23ea1690c6b34f03": "Voice input uses the first connected microphone in this list. A wired or Bluetooth microphone is added by name the first time you dictate with it connected; until then it falls under Other. Swipe left on a named microphone to forget it. Android may still use a different microphone if the preferred one can’t be routed.", "ed72aea6c71f7f6d": "Voice input uses the first connected microphone in this list. A wired or Bluetooth microphone is added by name the first time you dictate with it connected; until then it falls under Other. Swipe left on a named microphone to forget it.", + "55d10b17c262bf53": "Dictation language", + "2bc9b4068b479b4f": "Device language", + "af8339c1f8150347": "Voice input transcribes on this device. The first use of a language downloads it.", "49295375b18e1eaa": "{title}, {kind}, {position} of {count}", "ae4287de15deb58a": "Forget", "2595c662f9daa600": "Forget {title}", @@ -3940,6 +3944,7 @@ "28ddc910129103ae": "preferred microphone", "de274992a7c156aa": "microphone order", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "language", "02ac58b798da9931": "automations", "c4f44820c26e91c9": "schedule", "5ca8399aefd2acaf": "recurring", @@ -3948,7 +3953,6 @@ "b18d8b097eb4a3c2": "overview", "a8675ab06a18c426": "checkouts", "e44e1efba0742a8c": "delete project", - "3358b338bb494339": "language", "a3ff3275026d0318": "locale", "bbcff924e7734cee": "translation", "a67bb044f1d885bf": "english", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 55d4e81456cc5..eec5c98c9ad2a 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "La transcripción de voz no pudo preparar este idioma. Revisa {service} e inténtalo de nuevo.", "490f22de47fe7ee8": "Falló la transcripción de voz.", "e29263a611de039f": "La transcripción de voz requiere un dispositivo compatible con {platform} o posterior.", + "324eb1b534f4dd49": "La transcripción de voz no admite este idioma.", "111ee7a49fa0717c": "La transcripción de voz no pudo preparar este idioma.", "69a56aab78773a39": "La transcripción de voz no admite ninguno de tus idiomas.", "698777de597615cd": "Esta conexión no puede cambiar los adjuntos.", @@ -3787,6 +3788,9 @@ "58b5dfda390dfa7c": "Orden preferido", "23ea1690c6b34f03": "La entrada de voz usa el primer micrófono conectado de esta lista. Un micrófono con cable o Bluetooth se añade por su nombre la primera vez que dictas con él conectado; hasta entonces aparece en Otros. Desliza hacia la izquierda sobre un micrófono con nombre para olvidarlo. Android puede usar otro micrófono si no puede enrutar el preferido.", "ed72aea6c71f7f6d": "La entrada de voz usa el primer micrófono conectado de esta lista. Un micrófono con cable o Bluetooth se añade por su nombre la primera vez que dictas con él conectado; hasta entonces aparece en Otros. Desliza hacia la izquierda sobre un micrófono con nombre para olvidarlo.", + "55d10b17c262bf53": "Idioma de dictado", + "2bc9b4068b479b4f": "Idioma del dispositivo", + "af8339c1f8150347": "La entrada de voz se transcribe en este dispositivo. La primera vez que se usa un idioma, se descarga.", "49295375b18e1eaa": "{title}, {kind}, {position} de {count}", "ae4287de15deb58a": "Olvidar", "2595c662f9daa600": "Olvidar {title}", @@ -3933,6 +3937,7 @@ "28ddc910129103ae": "micrófono preferido", "de274992a7c156aa": "orden de micrófonos", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "idioma", "02ac58b798da9931": "automatizaciones", "c4f44820c26e91c9": "programación", "5ca8399aefd2acaf": "recurrente", @@ -3941,7 +3946,6 @@ "b18d8b097eb4a3c2": "resumen", "a8675ab06a18c426": "checkouts", "e44e1efba0742a8c": "eliminar proyecto", - "3358b338bb494339": "idioma", "a3ff3275026d0318": "configuración regional", "bbcff924e7734cee": "traducción", "a67bb044f1d885bf": "inglés", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 245547981f3dc..c67f0f1f11a07 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "La transcription vocale n’a pas pu préparer cette langue. Vérifiez {service} et réessayez.", "490f22de47fe7ee8": "La transcription vocale a échoué.", "e29263a611de039f": "La transcription vocale nécessite un appareil compatible avec {platform} ou une version ultérieure.", + "324eb1b534f4dd49": "La transcription vocale ne prend pas en charge cette langue.", "111ee7a49fa0717c": "La transcription vocale n’a pas pu préparer cette langue.", "69a56aab78773a39": "La transcription vocale ne prend en charge aucune de vos langues.", "698777de597615cd": "Cette connexion ne peut pas modifier les pièces jointes.", @@ -3787,6 +3788,9 @@ "58b5dfda390dfa7c": "Ordre de préférence", "23ea1690c6b34f03": "La saisie vocale utilise le premier microphone connecté de cette liste. Un microphone filaire ou Bluetooth est ajouté par son nom la première fois que vous dictez avec lui ; d’ici là, il est classé dans Autre. Balayez vers la gauche sur un microphone nommé pour l’oublier. Android peut quand même utiliser un autre microphone si le microphone préféré ne peut pas être sélectionné.", "ed72aea6c71f7f6d": "La saisie vocale utilise le premier microphone connecté de cette liste. Un microphone filaire ou Bluetooth est ajouté par son nom la première fois que vous dictez avec lui ; d’ici là, il est classé dans Autre. Balayez vers la gauche sur un microphone nommé pour l’oublier.", + "55d10b17c262bf53": "Langue de dictée", + "2bc9b4068b479b4f": "Langue de l’appareil", + "af8339c1f8150347": "La saisie vocale est transcrite sur cet appareil. Une langue est téléchargée lors de sa première utilisation.", "49295375b18e1eaa": "{title}, {kind}, {position} sur {count}", "ae4287de15deb58a": "Oublier", "2595c662f9daa600": "Oublier {title}", @@ -3933,6 +3937,7 @@ "28ddc910129103ae": "microphone préféré", "de274992a7c156aa": "ordre des microphones", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "langue", "02ac58b798da9931": "automatisations", "c4f44820c26e91c9": "planification", "5ca8399aefd2acaf": "récurrent", @@ -3941,7 +3946,6 @@ "b18d8b097eb4a3c2": "vue d’ensemble", "a8675ab06a18c426": "checkouts", "e44e1efba0742a8c": "supprimer le projet", - "3358b338bb494339": "langue", "a3ff3275026d0318": "paramètres régionaux", "bbcff924e7734cee": "traduction", "a67bb044f1d885bf": "anglais", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index a62452cddc89d..4dfd157044894 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "音声文字起こしでこの言語を準備できませんでした。{service} を確認して、もう一度お試しください。", "490f22de47fe7ee8": "音声文字起こしに失敗しました。", "e29263a611de039f": "音声文字起こしには、{platform} 以降を搭載した対応デバイスが必要です。", + "324eb1b534f4dd49": "音声文字起こしはこの言語に対応していません。", "111ee7a49fa0717c": "音声文字起こしでこの言語を準備できませんでした。", "69a56aab78773a39": "音声文字起こしはお使いの言語のいずれにも対応していません。", "698777de597615cd": "この接続では添付ファイルを変更できません。", @@ -3783,6 +3784,9 @@ "58b5dfda390dfa7c": "優先順", "23ea1690c6b34f03": "音声入力には、この一覧で最初に接続されているマイクを使用します。有線または Bluetooth のマイクは、接続した状態で初めて音声入力したときに名前付きで追加されます。それまでは「その他」に含まれます。名前付きのマイクを左にスワイプすると削除できます。優先するマイクにルーティングできない場合、Android は別のマイクを使うことがあります。", "ed72aea6c71f7f6d": "音声入力には、この一覧で最初に接続されているマイクを使用します。有線または Bluetooth のマイクは、接続した状態で初めて音声入力したときに名前付きで追加されます。それまでは「その他」に含まれます。名前付きのマイクを左にスワイプすると削除できます。", + "55d10b17c262bf53": "音声入力の言語", + "2bc9b4068b479b4f": "デバイスの言語", + "af8339c1f8150347": "音声はこのデバイスで文字起こしされます。言語を初めて使用するときにダウンロードされます。", "49295375b18e1eaa": "{title}、{kind}、{position} / {count}", "ae4287de15deb58a": "削除", "2595c662f9daa600": "{title} を削除", @@ -3929,6 +3933,7 @@ "28ddc910129103ae": "優先するマイク", "de274992a7c156aa": "マイクの順序", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "言語", "02ac58b798da9931": "自動化", "c4f44820c26e91c9": "スケジュール", "5ca8399aefd2acaf": "繰り返し", @@ -3937,7 +3942,6 @@ "b18d8b097eb4a3c2": "概要", "a8675ab06a18c426": "チェックアウト", "e44e1efba0742a8c": "プロジェクトを削除", - "3358b338bb494339": "言語", "a3ff3275026d0318": "ロケール", "bbcff924e7734cee": "翻訳", "a67bb044f1d885bf": "英語", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 87195d1e59336..1106649af3895 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "음성 받아쓰기에서 이 언어를 준비할 수 없습니다. {service}을(를) 확인하고 다시 시도하세요.", "490f22de47fe7ee8": "음성 받아쓰기에 실패했습니다.", "e29263a611de039f": "음성 받아쓰기를 사용하려면 {platform} 이상을 실행하는 지원 기기가 필요합니다.", + "324eb1b534f4dd49": "음성 전사는 이 언어를 지원하지 않습니다.", "111ee7a49fa0717c": "음성 받아쓰기에서 이 언어를 준비할 수 없습니다.", "69a56aab78773a39": "음성 받아쓰기가 사용자의 언어를 지원하지 않습니다.", "698777de597615cd": "이 연결로는 첨부 파일을 변경할 수 없습니다.", @@ -3787,6 +3788,9 @@ "58b5dfda390dfa7c": "선호 순서", "23ea1690c6b34f03": "음성 입력은 이 목록에서 처음으로 연결된 마이크를 사용합니다. 유선 또는 블루투스 마이크는 연결된 상태에서 처음 받아쓰기할 때 이름으로 추가되며, 그 전까지는 기타에 포함됩니다. 이름이 있는 마이크를 삭제하려면 왼쪽으로 스와이프하세요. 선호하는 마이크로 연결할 수 없으면 Android가 다른 마이크를 사용할 수 있습니다.", "ed72aea6c71f7f6d": "음성 입력은 이 목록에서 처음으로 연결된 마이크를 사용합니다. 유선 또는 블루투스 마이크는 연결된 상태에서 처음 받아쓰기할 때 이름으로 추가되며, 그 전까지는 기타에 포함됩니다. 이름이 있는 마이크를 삭제하려면 왼쪽으로 스와이프하세요.", + "55d10b17c262bf53": "받아쓰기 언어", + "2bc9b4068b479b4f": "기기 언어", + "af8339c1f8150347": "음성 입력은 이 기기에서 전사됩니다. 언어를 처음 사용하면 다운로드됩니다.", "49295375b18e1eaa": "{title}, {kind}, {count}개 중 {position}번째", "ae4287de15deb58a": "삭제", "2595c662f9daa600": "{title} 삭제", @@ -3933,6 +3937,7 @@ "28ddc910129103ae": "선호 마이크", "de274992a7c156aa": "마이크 순서", "1a45d942eafad9f9": "블루투스", + "3358b338bb494339": "언어", "02ac58b798da9931": "자동화", "c4f44820c26e91c9": "일정", "5ca8399aefd2acaf": "반복", @@ -3941,7 +3946,6 @@ "b18d8b097eb4a3c2": "개요", "a8675ab06a18c426": "체크아웃", "e44e1efba0742a8c": "프로젝트 삭제", - "3358b338bb494339": "언어", "a3ff3275026d0318": "로캘", "bbcff924e7734cee": "번역", "a67bb044f1d885bf": "영어", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index fb5d60acdbd89..6e5f5534a05eb 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "A transcrição de voz não conseguiu preparar este idioma. Verifique {service} e tente novamente.", "490f22de47fe7ee8": "A transcrição de voz falhou.", "e29263a611de039f": "A transcrição de voz exige um dispositivo compatível com {platform} ou posterior.", + "324eb1b534f4dd49": "A transcrição de voz não oferece suporte a este idioma.", "111ee7a49fa0717c": "A transcrição de voz não conseguiu preparar este idioma.", "69a56aab78773a39": "A transcrição de voz não suporta nenhum dos seus idiomas.", "698777de597615cd": "Esta conexão não pode alterar anexos.", @@ -3787,6 +3788,9 @@ "58b5dfda390dfa7c": "Ordem de preferência", "23ea1690c6b34f03": "A entrada de voz usa o primeiro microfone conectado desta lista. Um microfone com fio ou Bluetooth é adicionado pelo nome na primeira vez que você dita com ele conectado; até lá, ele fica em Outros. Deslize para a esquerda em um microfone com nome para esquecê-lo. O Android ainda pode usar outro microfone se o preferido não puder ser roteado.", "ed72aea6c71f7f6d": "A entrada de voz usa o primeiro microfone conectado desta lista. Um microfone com fio ou Bluetooth é adicionado pelo nome na primeira vez que você dita com ele conectado; até lá, ele fica em Outros. Deslize para a esquerda em um microfone com nome para esquecê-lo.", + "55d10b17c262bf53": "Idioma do ditado", + "2bc9b4068b479b4f": "Idioma do dispositivo", + "af8339c1f8150347": "A entrada de voz é transcrita neste dispositivo. O idioma é baixado no primeiro uso.", "49295375b18e1eaa": "{title}, {kind}, {position} de {count}", "ae4287de15deb58a": "Esquecer", "2595c662f9daa600": "Esquecer {title}", @@ -3933,6 +3937,7 @@ "28ddc910129103ae": "microfone preferido", "de274992a7c156aa": "ordem dos microfones", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "idioma", "02ac58b798da9931": "automações", "c4f44820c26e91c9": "agendamento", "5ca8399aefd2acaf": "recorrente", @@ -3941,7 +3946,6 @@ "b18d8b097eb4a3c2": "visão geral", "a8675ab06a18c426": "checkouts", "e44e1efba0742a8c": "excluir projeto", - "3358b338bb494339": "idioma", "a3ff3275026d0318": "localidade", "bbcff924e7734cee": "tradução", "a67bb044f1d885bf": "inglês", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index b5beca32c6869..9a27b35b3adf0 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "Расшифровка голоса не смогла подготовить этот язык. Проверьте {service} и попробуйте снова.", "490f22de47fe7ee8": "Не удалось расшифровать голос.", "e29263a611de039f": "Для расшифровки голоса нужно поддерживаемое устройство с {platform} или новее.", + "324eb1b534f4dd49": "Расшифровка речи не поддерживает этот язык.", "111ee7a49fa0717c": "Расшифровка голоса не смогла подготовить этот язык.", "69a56aab78773a39": "Расшифровка голоса не поддерживает ни один из ваших языков.", "698777de597615cd": "Это подключение не может менять вложения.", @@ -3841,6 +3842,9 @@ "58b5dfda390dfa7c": "Порядок предпочтения", "23ea1690c6b34f03": "Голосовой ввод использует первый подключённый микрофон из этого списка. Проводной или Bluetooth-микрофон добавляется по имени, когда вы впервые диктуете с ним; до этого он попадает в «Другой». Смахните влево по названию микрофона, чтобы забыть его. Android всё равно может использовать другой микрофон, если предпочтительный нельзя подключить.", "ed72aea6c71f7f6d": "Голосовой ввод использует первый подключённый микрофон из этого списка. Проводной или Bluetooth-микрофон добавляется по имени, когда вы впервые диктуете с ним; до этого он попадает в «Другой». Смахните влево по названию микрофона, чтобы забыть его.", + "55d10b17c262bf53": "Язык диктовки", + "2bc9b4068b479b4f": "Язык устройства", + "af8339c1f8150347": "Голосовой ввод расшифровывается на этом устройстве. При первом использовании язык загружается.", "49295375b18e1eaa": "{title}, {kind}, {position} из {count}", "ae4287de15deb58a": "Забыть", "2595c662f9daa600": "Забыть {title}", @@ -3987,6 +3991,7 @@ "28ddc910129103ae": "предпочтительный микрофон", "de274992a7c156aa": "порядок микрофонов", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "язык", "02ac58b798da9931": "автоматизации", "c4f44820c26e91c9": "расписание", "5ca8399aefd2acaf": "повторяющиеся", @@ -3995,7 +4000,6 @@ "b18d8b097eb4a3c2": "обзор", "a8675ab06a18c426": "копии", "e44e1efba0742a8c": "удалить проект", - "3358b338bb494339": "язык", "a3ff3275026d0318": "локаль", "bbcff924e7734cee": "перевод", "a67bb044f1d885bf": "английский", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 28ed7e557146a..4116e4c75c62f 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -1593,6 +1593,7 @@ "adb6243652c21da4": "Rösttranskriberingen kunde inte förbereda det här språket. Kontrollera {service} och försök igen.", "490f22de47fe7ee8": "Rösttranskriberingen misslyckades.", "e29263a611de039f": "Rösttranskribering kräver en enhet som stöds med {platform} eller senare.", + "324eb1b534f4dd49": "Rösttranskribering stöder inte det här språket.", "111ee7a49fa0717c": "Rösttranskriberingen kunde inte förbereda det här språket.", "69a56aab78773a39": "Rösttranskribering stöder inte något av dina språk.", "698777de597615cd": "Den här anslutningen kan inte ändra bilagor.", @@ -3793,6 +3794,9 @@ "58b5dfda390dfa7c": "Föredragen ordning", "23ea1690c6b34f03": "Röstinmatning använder den första anslutna mikrofonen i listan. En trådbunden mikrofon eller Bluetooth-mikrofon läggs till med namn första gången du dikterar med den ansluten; fram till dess hamnar den under Annan. Svep åt vänster på en namngiven mikrofon för att glömma den. Android kan ändå använda en annan mikrofon om den föredragna inte kan dirigeras.", "ed72aea6c71f7f6d": "Röstinmatning använder den första anslutna mikrofonen i listan. En trådbunden mikrofon eller Bluetooth-mikrofon läggs till med namn första gången du dikterar med den ansluten; fram till dess hamnar den under Annan. Svep åt vänster på en namngiven mikrofon för att glömma den.", + "55d10b17c262bf53": "Dikteringsspråk", + "2bc9b4068b479b4f": "Enhetens språk", + "af8339c1f8150347": "Röstinmatning transkriberas på den här enheten. Ett språk laddas ner första gången det används.", "49295375b18e1eaa": "{title}, {kind}, {position} av {count}", "ae4287de15deb58a": "Glöm", "2595c662f9daa600": "Glöm {title}", @@ -3939,6 +3943,7 @@ "28ddc910129103ae": "föredragen mikrofon", "de274992a7c156aa": "mikrofonordning", "1a45d942eafad9f9": "bluetooth", + "3358b338bb494339": "språk", "02ac58b798da9931": "automatiseringar", "c4f44820c26e91c9": "schema", "5ca8399aefd2acaf": "återkommande", @@ -3947,7 +3952,6 @@ "b18d8b097eb4a3c2": "översikt", "a8675ab06a18c426": "utcheckningar", "e44e1efba0742a8c": "ta bort projekt", - "3358b338bb494339": "språk", "a3ff3275026d0318": "språkinställning", "bbcff924e7734cee": "översättning", "a67bb044f1d885bf": "engelska", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index 52857eda6cc8a..70b42e45f2b4b 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -1594,6 +1594,7 @@ "adb6243652c21da4": "语音转写无法准备此语言。请检查 {service} 后重试。", "490f22de47fe7ee8": "语音转写失败。", "e29263a611de039f": "语音转写需要搭载 {platform} 或更高版本的受支持设备。", + "324eb1b534f4dd49": "语音转写不支持此语言。", "111ee7a49fa0717c": "语音转写无法准备此语言。", "69a56aab78773a39": "语音转写不支持你的任何语言。", "698777de597615cd": "此连接无法更改附件。", @@ -3789,6 +3790,9 @@ "58b5dfda390dfa7c": "优先顺序", "23ea1690c6b34f03": "语音输入使用此列表中第一个已连接的麦克风。有线或蓝牙麦克风会在你首次连接它进行听写时按名称添加;在此之前它归入“其他”。在已命名的麦克风上向左滑动即可忘记它。如果无法路由到首选麦克风,Android 仍可能使用其他麦克风。", "ed72aea6c71f7f6d": "语音输入使用此列表中第一个已连接的麦克风。有线或蓝牙麦克风会在你首次连接它进行听写时按名称添加;在此之前它归入“其他”。在已命名的麦克风上向左滑动即可忘记它。", + "55d10b17c262bf53": "听写语言", + "2bc9b4068b479b4f": "设备语言", + "af8339c1f8150347": "语音输入在此设备上转写。首次使用某种语言时会下载该语言。", "49295375b18e1eaa": "{title},{kind},{position}/{count}", "ae4287de15deb58a": "移除", "2595c662f9daa600": "忘记 {title}", @@ -3935,6 +3939,7 @@ "28ddc910129103ae": "首选麦克风", "de274992a7c156aa": "麦克风顺序", "1a45d942eafad9f9": "蓝牙", + "3358b338bb494339": "语言", "02ac58b798da9931": "自动化", "c4f44820c26e91c9": "定时规则", "5ca8399aefd2acaf": "周期", @@ -3943,7 +3948,6 @@ "b18d8b097eb4a3c2": "概览", "a8675ab06a18c426": "工作副本", "e44e1efba0742a8c": "删除项目", - "3358b338bb494339": "语言", "a3ff3275026d0318": "区域", "bbcff924e7734cee": "翻译", "a67bb044f1d885bf": "英语", diff --git a/apps/mobile/src/lib/dictationLanguage.ts b/apps/mobile/src/lib/dictationLanguage.ts new file mode 100644 index 0000000000000..8967c05acb4b3 --- /dev/null +++ b/apps/mobile/src/lib/dictationLanguage.ts @@ -0,0 +1,34 @@ +/** 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)" }, + { 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; +/* oxlint-enable t3code/no-untranslated-copy */ + +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.android.ts b/apps/mobile/src/native/voiceTranscription.android.ts index f596b2a1940e6..433bbd428bb13 100644 --- a/apps/mobile/src/native/voiceTranscription.android.ts +++ b/apps/mobile/src/native/voiceTranscription.android.ts @@ -79,6 +79,11 @@ export async function getLocalVoiceTranscriber(): Promise( module: GoogleTranscriptionModule, signal: AbortSignal, diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index 5d08ecc9aa244..ecf915dac14ea 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -23,7 +23,7 @@ vi.mock("expo", () => ({ }), })); -import { getLocalVoiceTranscriber } from "./voiceTranscription.ios"; +import { getLocalVoiceTranscriber, getVoiceTranscriberForLocale } from "./voiceTranscription.ios"; function useLanguages(preferred: ReadonlyArray, appLocale: string) { mocks.preferredLanguages = preferred; @@ -241,4 +241,54 @@ describe("getLocalVoiceTranscriber", () => { expect(error).toBeInstanceOf(VoiceTranscriptionError); expect(error).toMatchObject({ code: "cancelled" }); }); + + it("keeps the device-language message when the device offers a single language", async () => { + useLanguages(["en-US"], "en-US"); + mocks.prepare.mockResolvedValue(null); + 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 () => { + useLanguages(["en-US"], "en-US"); + mocks.prepare.mockResolvedValue("pt-BR"); + mocks.transcribe.mockResolvedValue("olá"); + const options = { signal: new AbortController().signal }; + const prepared = await getVoiceTranscriberForLocale("pt-BR")!.prepare(options); + await prepared.transcribe("file:///voice.m4a", options); + + expect(mocks.prepare).toHaveBeenCalledWith("pt-BR"); + expect(mocks.transcribe).toHaveBeenCalledWith("file:///voice.m4a", "pt-BR"); + expect(prepared.locale).toBe("pt-BR"); + }); + + it("fails on a chosen locale the device cannot transcribe instead of falling back", async () => { + useLanguages(["en-US"], "en-US"); + mocks.prepare.mockResolvedValue(null); + const options = { signal: new AbortController().signal }; + + // 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); + expect(error).toMatchObject({ + code: "unsupported-locale", + message: "Voice transcription does not support this language.", + }); + expect(mocks.prepare).toHaveBeenCalledTimes(1); + expect(mocks.prepare).toHaveBeenCalledWith("de-DE"); + }); }); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index 9701036e5ac94..2a953efb645f1 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -48,12 +48,19 @@ export async function getLocalVoiceTranscriber(): Promise prepareVoiceTranscription(native, locales, options) }; + return { prepare: (options) => prepareVoiceTranscription(native, 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 { + if (!native) return null; + return { prepare: (options) => prepareVoiceTranscription(native, [locale], true, options) }; } async function prepareVoiceTranscription( native: AppleSpeechModule, locales: readonly string[], + chosen: boolean, { signal }: VoiceTranscriptionOptions, ): Promise { throwIfVoiceTranscriptionAborted(signal); @@ -69,7 +76,7 @@ async function prepareVoiceTranscription( } let locale = locales[0]!; - const model = prepareLocales(native, locales, signal).then((supported) => { + const model = prepareLocales(native, locales, chosen, signal).then((supported) => { locale = supported; }); // Recorder setup can fail before either consumer observes the model. @@ -104,13 +111,14 @@ async function prepareVoiceTranscription( async function prepareLocales( native: AppleSpeechModule, locales: readonly string[], + chosen: boolean, signal: AbortSignal, ): Promise { throwIfVoiceTranscriptionAborted(signal); let unsupported: VoiceTranscriptionError | undefined; for (const locale of locales) { try { - return await prepareLocale(native, locale, signal); + return await prepareLocale(native, locale, chosen, signal); } catch (error) { if (!isVoiceTranscriptionError(error) || error.code !== "unsupported-locale") throw error; unsupported = error; @@ -122,6 +130,7 @@ async function prepareLocales( async function prepareLocale( native: AppleSpeechModule, locale: string, + chosen: boolean, signal: AbortSignal, ): Promise { let supportedLocale: string | null; @@ -139,7 +148,9 @@ async function prepareLocale( if (supportedLocale === null) { throw new VoiceTranscriptionError({ code: "unsupported-locale", - message: 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.")), }); } return supportedLocale; diff --git a/apps/mobile/src/native/voiceTranscription.ts b/apps/mobile/src/native/voiceTranscription.ts index 496a862836a19..3388b2677d741 100644 --- a/apps/mobile/src/native/voiceTranscription.ts +++ b/apps/mobile/src/native/voiceTranscription.ts @@ -3,3 +3,7 @@ import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; export async function getLocalVoiceTranscriber(): Promise { return null; } + +export function getVoiceTranscriberForLocale(_locale: string): VoiceTranscriber | null { + return null; +} diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 71d095b0b4fb5..dc8fa24dfe9f3 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -21,6 +21,7 @@ import { import { ToolCallVisibility } from "@t3tools/contracts/settings"; 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"; @@ -165,6 +166,8 @@ export interface Preferences { /** The client `language` setting: a locale code or "system". Unset means English. */ readonly language?: string; readonly microphones?: ReadonlyArray; + /** Unset or null means dictation follows the device language. */ + readonly dictationLocale?: DictationLocale | null; readonly projectGroupingEnabled?: boolean; readonly projectGroupingMode?: SidebarProjectGroupingMode; readonly toolCallVisibility?: ToolCallVisibility; @@ -255,6 +258,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { followUpBehavior?: FollowUpBehavior; language?: string; microphones?: ReadonlyArray; + dictationLocale?: DictationLocale | null; projectGroupingEnabled?: boolean; projectGroupingMode?: SidebarProjectGroupingMode; toolCallVisibility?: ToolCallVisibility; @@ -378,6 +382,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 53017052a2a01..9c06b070f5071 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -261,6 +261,10 @@ microphone on iOS. Swipe a device left to forget it. Android may use another inp when the preferred microphone cannot be routed. Devices with the same name may share a saved preference, but simultaneous same-name inputs remain separately selectable. +On iOS, to choose the language on-device dictation transcribes, such as Brazilian Portuguese, +pick it under **Settings → Voice → Dictation language**. **Device language** is the default +and uses your preferred languages as described above. Android always transcribes the device language. + T3 Code deletes the temporary recording from your phone after transcription or cancellation. The transcript stays in your draft until you send the message to the agent.