Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/mobile/src/features/settings/SettingsVoiceRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.",
)}
</Text>
{/* Google's on-device recognizer on Android always uses the device language. */}
{Platform.OS === "ios" && !grant && !sheetEnvironment ? (
<>
<SettingsSection title={gt("Dictation language")}>
<SettingsChoiceRow
label={gt("Device language")}
selected={ready && dictationLocale === null}
disabled={!ready}
onPress={() => savePreferences({ dictationLocale: null })}
/>
{DICTATION_LANGUAGES.map((language) => (
<SettingsChoiceRow
key={language.locale}
label={language.label}
selected={dictationLocale === language.locale}
separated
disabled={!ready}
onPress={() => savePreferences({ dictationLocale: language.locale })}
/>
))}
</SettingsSection>
<Text className="px-2 text-sm text-foreground-muted">
{gt(
"Voice input transcribes on this device. The first use of a language downloads it.",
)}
</Text>
</>
) : null}
</ScrollView>
</SettingsScreen>
);
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/settings/settings-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),
Expand Down
48 changes: 46 additions & 2 deletions apps/mobile/src/features/voice-input/VoiceInputProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -57,6 +61,17 @@ function keepScreenAwake(tag: string): () => void {
export const deviceMicrophoneOrder = (saved?: ReadonlyArray<MicrophoneEntry>) =>
microphoneOrder(saved, Platform.OS === "android" ? "android" : "ios");

type MobilePreferencesResult = Atom.Type<typeof mobilePreferencesAtom>;

/** 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"
Expand Down Expand Up @@ -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<MobilePreferencesResult | null>((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 () => {
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -3938,6 +3942,7 @@
"28ddc910129103ae": "bevorzugtes mikrofon",
"de274992a7c156aa": "mikrofonreihenfolge",
"1a45d942eafad9f9": "bluetooth",
"3358b338bb494339": "sprache",
"02ac58b798da9931": "automatisierungen",
"c4f44820c26e91c9": "zeitplan",
"5ca8399aefd2acaf": "wiederkehrend",
Expand All @@ -3946,7 +3951,6 @@
"b18d8b097eb4a3c2": "übersicht",
"a8675ab06a18c426": "checkouts",
"e44e1efba0742a8c": "projekt löschen",
"3358b338bb494339": "sprache",
"a3ff3275026d0318": "gebietsschema",
"bbcff924e7734cee": "übersetzung",
"a67bb044f1d885bf": "englisch",
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -3940,6 +3944,7 @@
"28ddc910129103ae": "preferred microphone",
"de274992a7c156aa": "microphone order",
"1a45d942eafad9f9": "bluetooth",
"3358b338bb494339": "language",
"02ac58b798da9931": "automations",
"c4f44820c26e91c9": "schedule",
"5ca8399aefd2acaf": "recurring",
Expand All @@ -3948,7 +3953,6 @@
"b18d8b097eb4a3c2": "overview",
"a8675ab06a18c426": "checkouts",
"e44e1efba0742a8c": "delete project",
"3358b338bb494339": "language",
"a3ff3275026d0318": "locale",
"bbcff924e7734cee": "translation",
"a67bb044f1d885bf": "english",
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -3933,6 +3937,7 @@
"28ddc910129103ae": "micrófono preferido",
"de274992a7c156aa": "orden de micrófonos",
"1a45d942eafad9f9": "bluetooth",
"3358b338bb494339": "idioma",
"02ac58b798da9931": "automatizaciones",
"c4f44820c26e91c9": "programación",
"5ca8399aefd2acaf": "recurrente",
Expand All @@ -3941,7 +3946,6 @@
"b18d8b097eb4a3c2": "resumen",
"a8675ab06a18c426": "checkouts",
"e44e1efba0742a8c": "eliminar proyecto",
"3358b338bb494339": "idioma",
"a3ff3275026d0318": "configuración regional",
"bbcff924e7734cee": "traducción",
"a67bb044f1d885bf": "inglés",
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -3933,6 +3937,7 @@
"28ddc910129103ae": "microphone préféré",
"de274992a7c156aa": "ordre des microphones",
"1a45d942eafad9f9": "bluetooth",
"3358b338bb494339": "langue",
"02ac58b798da9931": "automatisations",
"c4f44820c26e91c9": "planification",
"5ca8399aefd2acaf": "récurrent",
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@
"adb6243652c21da4": "音声文字起こしでこの言語を準備できませんでした。{service} を確認して、もう一度お試しください。",
"490f22de47fe7ee8": "音声文字起こしに失敗しました。",
"e29263a611de039f": "音声文字起こしには、{platform} 以降を搭載した対応デバイスが必要です。",
"324eb1b534f4dd49": "音声文字起こしはこの言語に対応していません。",
"111ee7a49fa0717c": "音声文字起こしでこの言語を準備できませんでした。",
"69a56aab78773a39": "音声文字起こしはお使いの言語のいずれにも対応していません。",
"698777de597615cd": "この接続では添付ファイルを変更できません。",
Expand Down Expand Up @@ -3783,6 +3784,9 @@
"58b5dfda390dfa7c": "優先順",
"23ea1690c6b34f03": "音声入力には、この一覧で最初に接続されているマイクを使用します。有線または Bluetooth のマイクは、接続した状態で初めて音声入力したときに名前付きで追加されます。それまでは「その他」に含まれます。名前付きのマイクを左にスワイプすると削除できます。優先するマイクにルーティングできない場合、Android は別のマイクを使うことがあります。",
"ed72aea6c71f7f6d": "音声入力には、この一覧で最初に接続されているマイクを使用します。有線または Bluetooth のマイクは、接続した状態で初めて音声入力したときに名前付きで追加されます。それまでは「その他」に含まれます。名前付きのマイクを左にスワイプすると削除できます。",
"55d10b17c262bf53": "音声入力の言語",
"2bc9b4068b479b4f": "デバイスの言語",
"af8339c1f8150347": "音声はこのデバイスで文字起こしされます。言語を初めて使用するときにダウンロードされます。",
"49295375b18e1eaa": "{title}、{kind}、{position} / {count}",
"ae4287de15deb58a": "削除",
"2595c662f9daa600": "{title} を削除",
Expand Down Expand Up @@ -3929,6 +3933,7 @@
"28ddc910129103ae": "優先するマイク",
"de274992a7c156aa": "マイクの順序",
"1a45d942eafad9f9": "bluetooth",
"3358b338bb494339": "言語",
"02ac58b798da9931": "自動化",
"c4f44820c26e91c9": "スケジュール",
"5ca8399aefd2acaf": "繰り返し",
Expand All @@ -3937,7 +3942,6 @@
"b18d8b097eb4a3c2": "概要",
"a8675ab06a18c426": "チェックアウト",
"e44e1efba0742a8c": "プロジェクトを削除",
"3358b338bb494339": "言語",
"a3ff3275026d0318": "ロケール",
"bbcff924e7734cee": "翻訳",
"a67bb044f1d885bf": "英語",
Expand Down
Loading
Loading