diff --git a/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriber.kt b/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriber.kt index ce722817dd131..4ecd76878e768 100644 --- a/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriber.kt +++ b/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriber.kt @@ -31,21 +31,27 @@ private val recognitionModes = listOf( SpeechRecognizerOptions.Mode.MODE_BASIC ) -internal suspend fun isGoogleVoiceTranscriptionSupported( +internal data class GoogleVoiceSupport(val mode: Int, val downloaded: Boolean) + +/** The mode `prepareGoogleVoiceTranscription` would pick, without downloading its model. */ +internal suspend fun probeGoogleVoiceTranscription( createClient: (Int) -> GoogleSpeechClient -): Boolean { +): GoogleVoiceSupport? { for (mode in recognitionModes) { - createClient(mode).use { client -> - when (checkModelSupport(client)) { - FeatureStatus.AVAILABLE, - FeatureStatus.DOWNLOADABLE, - FeatureStatus.DOWNLOADING -> return true - } + val status = createClient(mode).use { checkModelSupport(it) } + if (status in supportedStatuses) { + return GoogleVoiceSupport(mode, downloaded = status == FeatureStatus.AVAILABLE) } } - return false + return null } +private val supportedStatuses = setOf( + FeatureStatus.AVAILABLE, + FeatureStatus.DOWNLOADABLE, + FeatureStatus.DOWNLOADING +) + internal suspend fun prepareGoogleVoiceTranscription( createClient: (Int) -> GoogleSpeechClient ): Int { diff --git a/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/T3VoiceTranscriptionModule.kt b/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/T3VoiceTranscriptionModule.kt index 3218690967f97..918b25c86bf80 100644 --- a/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/T3VoiceTranscriptionModule.kt +++ b/apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/T3VoiceTranscriptionModule.kt @@ -2,6 +2,7 @@ package expo.modules.t3voicetranscription import android.content.res.Resources import android.os.Build +import com.google.mlkit.genai.speechrecognition.SpeechRecognizerOptions import expo.modules.kotlin.Promise import expo.modules.kotlin.functions.Coroutine import expo.modules.kotlin.modules.Module @@ -31,14 +32,20 @@ class T3VoiceTranscriptionModule : Module() { defineDecodeRecording() - AsyncFunction("checkAvailability").Coroutine { + AsyncFunction("checkAvailability").Coroutine?> { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { - false + null } else { withContext(Dispatchers.IO) { val context = requireNotNull(appContext.reactContext) val locale = speechLocale(Resources.getSystem().configuration.locales[0]) - isGoogleVoiceTranscriptionSupported { MlKitSpeechClient(context, locale, it) } + probeGoogleVoiceTranscription { MlKitSpeechClient(context, locale, it) }?.let { + mapOf( + "language" to locale.displayName, + "advanced" to (it.mode == SpeechRecognizerOptions.Mode.MODE_ADVANCED), + "downloaded" to it.downloaded + ) + } } } } diff --git a/apps/mobile/modules/t3-voice-transcription/android/src/test/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriberTest.kt b/apps/mobile/modules/t3-voice-transcription/android/src/test/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriberTest.kt index 445411bbb6957..68cec512d1d52 100644 --- a/apps/mobile/modules/t3-voice-transcription/android/src/test/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriberTest.kt +++ b/apps/mobile/modules/t3-voice-transcription/android/src/test/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriberTest.kt @@ -91,23 +91,43 @@ class GoogleVoiceTranscriberTest { } @Test - fun checksSupportWithoutDownloadingAndClosesProbedClients() = runBlocking { - for ((advancedStatus, basicStatus, supported) in listOf( - Triple(FeatureStatus.AVAILABLE, FeatureStatus.UNAVAILABLE, true), - Triple(FeatureStatus.DOWNLOADABLE, FeatureStatus.UNAVAILABLE, true), - Triple(FeatureStatus.DOWNLOADING, FeatureStatus.UNAVAILABLE, true), - Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.AVAILABLE, true), - Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.DOWNLOADABLE, true), - Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.DOWNLOADING, true), - Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.UNAVAILABLE, false) + fun probesSupportWithoutDownloadingAndClosesProbedClients() = runBlocking { + val advanced = SpeechRecognizerOptions.Mode.MODE_ADVANCED + val basic = SpeechRecognizerOptions.Mode.MODE_BASIC + for ((advancedStatus, basicStatus, expected) in listOf( + Triple( + FeatureStatus.AVAILABLE, + FeatureStatus.UNAVAILABLE, + GoogleVoiceSupport(advanced, true) + ), + Triple( + FeatureStatus.DOWNLOADABLE, + FeatureStatus.AVAILABLE, + GoogleVoiceSupport(advanced, false) + ), + Triple( + FeatureStatus.DOWNLOADING, + FeatureStatus.UNAVAILABLE, + GoogleVoiceSupport(advanced, false) + ), + Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.AVAILABLE, GoogleVoiceSupport(basic, true)), + Triple( + FeatureStatus.UNAVAILABLE, + FeatureStatus.DOWNLOADABLE, + GoogleVoiceSupport(basic, false) + ), + Triple( + FeatureStatus.UNAVAILABLE, + FeatureStatus.DOWNLOADING, + GoogleVoiceSupport(basic, false) + ), + Triple(FeatureStatus.UNAVAILABLE, FeatureStatus.UNAVAILABLE, null) )) { val clients = mutableListOf() assertEquals( - supported, - isGoogleVoiceTranscriptionSupported { mode -> - Client( - if (mode == SpeechRecognizerOptions.Mode.MODE_ADVANCED) advancedStatus else basicStatus - ).also { clients.add(it) } + expected, + probeGoogleVoiceTranscription { mode -> + Client(if (mode == advanced) advancedStatus else basicStatus).also { clients.add(it) } } ) assertTrue(clients.all { it.closed && it.downloads == 0 }) diff --git a/apps/mobile/src/components/ui/ListChoiceRow.tsx b/apps/mobile/src/components/ui/ListChoiceRow.tsx index 0b320296bfe69..d819d32e9cd4a 100644 --- a/apps/mobile/src/components/ui/ListChoiceRow.tsx +++ b/apps/mobile/src/components/ui/ListChoiceRow.tsx @@ -10,6 +10,8 @@ import { RowPressable } from "./RowPressable"; export function ListChoiceRow(props: { readonly label: string; + /** Defaults to `label`; set it when `meta` carries information a screen reader needs. */ + readonly accessibilityLabel?: string; readonly leading?: ReactNode; readonly description?: string; readonly meta?: ReactNode; @@ -22,7 +24,7 @@ export function ListChoiceRow(props: { return ( { + refreshTranscriber(); + }, [refreshTranscriber]); + const localEngine = + transcriber === null || transcriber === "checking" ? null : transcriber.engine; const grant = useAtomValue(voiceGrantAtom); const { environments, isReady } = useEnvironments(); const grantEnvironment = grant @@ -293,10 +319,25 @@ export function SettingsVoiceRouteScreen() { contentContainerClassName="gap-3 px-5 pt-4" contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} > - + + {localEngineLabel(localEngine, m)} + + ) : undefined + } selected={!grant && !sheetEnvironment} onPress={() => { setCloudSheet(null); diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index 6e891dd04e7e9..8a830e5eea74c 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -13,14 +13,14 @@ import { preferredMicrophoneInput, rememberMicrophones, } from "../../lib/microphonePriority"; -import { getLocalVoiceTranscriber } from "../../native/voiceTranscription"; +import { + getLocalVoiceTranscriber, + type LocalVoiceTranscriber, +} from "../../native/voiceTranscription"; import { createVoiceRecorder } from "../../native/voiceRecorder"; import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; import { getNativeShowcaseScene } from "../showcase/nativeShowcaseScene"; -import { - voiceInputBlocksSubmission, - type VoiceTranscriber, -} from "@t3tools/client-runtime/voice-input"; +import { voiceInputBlocksSubmission } from "@t3tools/client-runtime/voice-input"; import { createLazyVoiceRecorder } from "./lazyVoiceRecorder"; import { VOICE_WAVEFORM_SAMPLE_COUNT } from "./voiceInputMetering"; import { VoiceInputSession } from "./voiceInputSession"; @@ -57,7 +57,7 @@ export const deviceMicrophoneOrder = (saved?: ReadonlyArray) => /** "checking" until the first availability probe settles; re-probed on foreground. */ export const localVoiceTranscriberAtom = makePermissionStatusAtom< - VoiceTranscriber | null | "checking" + LocalVoiceTranscriber | null | "checking" >({ label: "mobile:voice-input:transcriber", initial: "checking", diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index c9d43d96b3eb8..c56f44e38ddd0 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -3607,6 +3607,13 @@ "2638893eacbb570f": "Das Mikrofon des Autos", "2c14a72bd967f644": "Diktieren auf diesem Gerät erfordert Android 12 oder neuer und Google-Sprachdienste, die deine Sprache unterstützen. Die Spracheingabe deiner Tastatur ist davon unabhängig.", "1c8c24c85e11a338": "Diktieren auf diesem Gerät erfordert iOS 26 oder neuer, ein unterstütztes Gerät und eine unterstützte Sprache. Das Diktieren deiner Tastatur ist davon unabhängig.", + "3dae353469c92182": "Basis ist das Standard-Sprachmodell von Google. Erweitert nutzt Gemini Nano auf unterstützten Smartphones und ist meist genauer. Die Spracheingabe der Tastatur ist unabhängig davon.", + "970e65a607981efa": "Die Diktierfunktion der Tastatur ist unabhängig davon.", + "0632395d31287ad5": "Apple-Spracherkennung auf dem Gerät", + "3606e6ccbe6402a4": "Download bei erster Nutzung", + "8da94cf9944b5a42": "Google-Spracherkennung auf dem Gerät · {mode} · {language}", + "2757a250104b4b7e": "Erweitert", + "e698e61f5dbb414f": "Basis", "6e9c96e6b25914bd": "Transkriptionswahl konnte nicht gespeichert werden", "a808542c8c257a51": "Diktieren in einer Umgebung ist für diese Sitzung aus. Speichere erneut, bevor du die App schließt, sonst kehrt deine vorherige Wahl beim Neustart eventuell zurück.", "88b8883d4b35039b": "Transkription nicht verfügbar", @@ -3616,6 +3623,7 @@ "5388ec5b413a1243": "Umgebung verwenden", "67c75c28267889b3": "Methode auf {environment}", "13604264948aba9d": "Transkribieren auf", + "2a057e821449a44e": "Dieses Gerät, {engine}", "e3b080ff21a4a1ee": "Audio bleibt auf diesem Gerät und wird hier transkribiert.", "c6cf6f916fbad786": "Zuvor ausgewählte Umgebung", "5180a62fd93aac38": "Nicht mehr gekoppelt", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 7a89a1cf37c22..62f284f935e1c 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -3608,6 +3608,13 @@ "2638893eacbb570f": "The car’s microphone", "2c14a72bd967f644": "Dictation on this device needs Android 12 or later and Google speech services that support your language. Your keyboard’s voice typing is separate.", "1c8c24c85e11a338": "Dictation on this device needs iOS 26 or later, a supported device, and a supported language. Your keyboard’s dictation is separate.", + "3dae353469c92182": "Basic is Google’s standard speech model. Advanced uses Gemini Nano on supported phones and is usually more accurate. Your keyboard’s voice typing is separate.", + "970e65a607981efa": "Your keyboard’s dictation is separate.", + "0632395d31287ad5": "Apple on-device speech", + "3606e6ccbe6402a4": "Downloads on first use", + "8da94cf9944b5a42": "Google on-device speech · {mode} · {language}", + "2757a250104b4b7e": "Advanced", + "e698e61f5dbb414f": "Basic", "6e9c96e6b25914bd": "Could not save transcription choice", "a808542c8c257a51": "Dictation on an environment is off for this session. Save again before closing the app, or your previous choice may return when it restarts.", "88b8883d4b35039b": "Transcription unavailable", @@ -3617,6 +3624,7 @@ "5388ec5b413a1243": "Use environment", "67c75c28267889b3": "Method on {environment}", "13604264948aba9d": "Transcribe on", + "2a057e821449a44e": "This device, {engine}", "e3b080ff21a4a1ee": "Audio stays on this device and is transcribed here.", "c6cf6f916fbad786": "Previously selected environment", "5180a62fd93aac38": "No longer paired", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 288dbfc7da2cf..91f5e5b252d10 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -3602,6 +3602,13 @@ "2638893eacbb570f": "El micrófono del coche", "2c14a72bd967f644": "El dictado en este dispositivo requiere Android 12 o posterior y servicios de voz de Google compatibles con tu idioma. El dictado por voz de tu teclado es independiente.", "1c8c24c85e11a338": "El dictado en este dispositivo requiere iOS 26 o posterior, un dispositivo compatible y un idioma compatible. El dictado de tu teclado es independiente.", + "3dae353469c92182": "Básico es el modelo de voz estándar de Google. Avanzado usa Gemini Nano en teléfonos compatibles y suele ser más preciso. El dictado del teclado es independiente.", + "970e65a607981efa": "El dictado del teclado es independiente.", + "0632395d31287ad5": "Reconocimiento de voz local de Apple", + "3606e6ccbe6402a4": "Se descarga al usarlo por primera vez", + "8da94cf9944b5a42": "Reconocimiento de voz local de Google · {mode} · {language}", + "2757a250104b4b7e": "Avanzado", + "e698e61f5dbb414f": "Básico", "6e9c96e6b25914bd": "No se pudo guardar la elección de transcripción", "a808542c8c257a51": "El dictado en un entorno está desactivado en esta sesión. Vuelve a guardar antes de cerrar la app o puede que vuelva tu elección anterior al reiniciarla.", "88b8883d4b35039b": "Transcripción no disponible", @@ -3611,6 +3618,7 @@ "5388ec5b413a1243": "Usar entorno", "67c75c28267889b3": "Método en {environment}", "13604264948aba9d": "Transcribir en", + "2a057e821449a44e": "Este dispositivo, {engine}", "e3b080ff21a4a1ee": "El audio se queda en este dispositivo y se transcribe aquí.", "c6cf6f916fbad786": "Entorno seleccionado anteriormente", "5180a62fd93aac38": "Ya no está emparejado", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 28ec2284fca74..f9405663e5e27 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -3602,6 +3602,13 @@ "2638893eacbb570f": "Le microphone de la voiture", "2c14a72bd967f644": "La dictée sur cet appareil nécessite Android 12 ou une version ultérieure et des services vocaux Google compatibles avec votre langue. La saisie vocale de votre clavier est distincte.", "1c8c24c85e11a338": "La dictée sur cet appareil nécessite iOS 26 ou une version ultérieure, un appareil compatible et une langue prise en charge. La dictée de votre clavier est distincte.", + "3dae353469c92182": "Basique est le modèle vocal standard de Google. Avancé utilise Gemini Nano sur les téléphones compatibles et est généralement plus précis. La dictée du clavier est indépendante.", + "970e65a607981efa": "La dictée du clavier est indépendante.", + "0632395d31287ad5": "Reconnaissance vocale Apple sur l’appareil", + "3606e6ccbe6402a4": "Téléchargement à la première utilisation", + "8da94cf9944b5a42": "Reconnaissance vocale Google sur l’appareil · {mode} · {language}", + "2757a250104b4b7e": "Avancé", + "e698e61f5dbb414f": "Basique", "6e9c96e6b25914bd": "Impossible d’enregistrer le choix de transcription", "a808542c8c257a51": "La dictée dans un environnement est désactivée pour cette session. Enregistrez à nouveau avant de fermer l’app, sinon votre choix précédent pourrait revenir au redémarrage.", "88b8883d4b35039b": "Transcription indisponible", @@ -3611,6 +3618,7 @@ "5388ec5b413a1243": "Utiliser l’environnement", "67c75c28267889b3": "Méthode sur {environment}", "13604264948aba9d": "Transcrire sur", + "2a057e821449a44e": "Cet appareil, {engine}", "e3b080ff21a4a1ee": "L’audio reste sur cet appareil et y est transcrit.", "c6cf6f916fbad786": "Environnement sélectionné précédemment", "5180a62fd93aac38": "Plus appairé", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index f6741fdb8b775..3026199970da3 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -3599,6 +3599,13 @@ "2638893eacbb570f": "車のマイク", "2c14a72bd967f644": "このデバイスでの音声入力には、Android 12 以降と、お使いの言語に対応した Google 音声サービスが必要です。キーボードの音声入力とは別のものです。", "1c8c24c85e11a338": "このデバイスでの音声入力には、iOS 26 以降、対応デバイス、対応言語が必要です。キーボードの音声入力とは別のものです。", + "3dae353469c92182": "基本モードは Google の標準音声モデルです。高度モードは対応するスマートフォンで Gemini Nano を使用し、通常は精度が高くなります。キーボードの音声入力は別の機能です。", + "970e65a607981efa": "キーボードの音声入力は別の機能です。", + "0632395d31287ad5": "Apple のオンデバイス音声認識", + "3606e6ccbe6402a4": "初回使用時にダウンロード", + "8da94cf9944b5a42": "Google のオンデバイス音声認識 · {mode} · {language}", + "2757a250104b4b7e": "高度", + "e698e61f5dbb414f": "基本", "6e9c96e6b25914bd": "文字起こしの選択を保存できませんでした", "a808542c8c257a51": "このセッションでは環境での音声入力がオフになっています。アプリを閉じる前にもう一度保存してください。保存しないと、再起動時に以前の選択に戻る場合があります。", "88b8883d4b35039b": "文字起こしを利用できません", @@ -3608,6 +3615,7 @@ "5388ec5b413a1243": "環境を使用", "67c75c28267889b3": "{environment} での方法", "13604264948aba9d": "文字起こしの実行場所", + "2a057e821449a44e": "このデバイス、{engine}", "e3b080ff21a4a1ee": "音声はこのデバイスから外に出ず、ここで文字起こしされます。", "c6cf6f916fbad786": "以前に選択した環境", "5180a62fd93aac38": "ペアリングが解除されています", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index b1ef20ba0f347..eadb4797c78ca 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -3603,6 +3603,13 @@ "2638893eacbb570f": "차량의 마이크", "2c14a72bd967f644": "이 기기에서 받아쓰기를 사용하려면 Android 12 이상과 사용자의 언어를 지원하는 Google 음성 서비스가 필요합니다. 키보드의 음성 입력과는 별개입니다.", "1c8c24c85e11a338": "이 기기에서 받아쓰기를 사용하려면 iOS 26 이상, 지원 기기, 지원 언어가 필요합니다. 키보드의 받아쓰기와는 별개입니다.", + "3dae353469c92182": "기본 모드는 Google의 표준 음성 모델입니다. 고급 모드는 지원되는 휴대전화에서 Gemini Nano를 사용하며 일반적으로 더 정확합니다. 키보드의 음성 입력은 별도 기능입니다.", + "970e65a607981efa": "키보드의 받아쓰기는 별도 기능입니다.", + "0632395d31287ad5": "Apple 기기 내 음성 인식", + "3606e6ccbe6402a4": "처음 사용할 때 다운로드", + "8da94cf9944b5a42": "Google 기기 내 음성 인식 · {mode} · {language}", + "2757a250104b4b7e": "고급", + "e698e61f5dbb414f": "기본", "6e9c96e6b25914bd": "받아쓰기 선택을 저장할 수 없습니다", "a808542c8c257a51": "이 세션에서는 환경의 받아쓰기가 꺼져 있습니다. 앱을 닫기 전에 다시 저장하지 않으면 다시 시작할 때 이전 선택으로 돌아갈 수 있습니다.", "88b8883d4b35039b": "받아쓰기를 사용할 수 없음", @@ -3612,6 +3619,7 @@ "5388ec5b413a1243": "환경 사용", "67c75c28267889b3": "{environment}의 방식", "13604264948aba9d": "받아쓰기 위치", + "2a057e821449a44e": "이 기기, {engine}", "e3b080ff21a4a1ee": "오디오는 이 기기에 남아 여기서 받아씁니다.", "c6cf6f916fbad786": "이전에 선택한 환경", "5180a62fd93aac38": "더 이상 페어링되지 않음", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index b40494fca3885..54a3e31a92ebf 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -3602,6 +3602,13 @@ "2638893eacbb570f": "O microfone do carro", "2c14a72bd967f644": "O ditado neste dispositivo exige Android 12 ou posterior e serviços de fala do Google que suportem seu idioma. A digitação por voz do seu teclado é separada.", "1c8c24c85e11a338": "O ditado neste dispositivo exige iOS 26 ou posterior, um dispositivo compatível e um idioma compatível. O ditado do seu teclado é separado.", + "3dae353469c92182": "Básico é o modelo de fala padrão do Google. Avançado usa o Gemini Nano em celulares compatíveis e costuma ser mais preciso. A digitação por voz do teclado é independente.", + "970e65a607981efa": "O ditado do teclado é independente.", + "0632395d31287ad5": "Reconhecimento de fala da Apple no dispositivo", + "3606e6ccbe6402a4": "Baixa no primeiro uso", + "8da94cf9944b5a42": "Reconhecimento de fala do Google no dispositivo · {mode} · {language}", + "2757a250104b4b7e": "Avançado", + "e698e61f5dbb414f": "Básico", "6e9c96e6b25914bd": "Não foi possível salvar a escolha de transcrição", "a808542c8c257a51": "O ditado em um ambiente está desativado nesta sessão. Salve novamente antes de fechar o app, ou sua escolha anterior pode voltar quando ele reiniciar.", "88b8883d4b35039b": "Transcrição indisponível", @@ -3611,6 +3618,7 @@ "5388ec5b413a1243": "Usar ambiente", "67c75c28267889b3": "Método em {environment}", "13604264948aba9d": "Transcrever em", + "2a057e821449a44e": "Este dispositivo, {engine}", "e3b080ff21a4a1ee": "O áudio fica neste dispositivo e é transcrito aqui.", "c6cf6f916fbad786": "Ambiente selecionado anteriormente", "5180a62fd93aac38": "Não está mais pareado", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index cadf07e57eda9..3552987255d40 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -3656,6 +3656,13 @@ "2638893eacbb570f": "Микрофон автомобиля", "2c14a72bd967f644": "Для диктовки на этом устройстве нужны Android 12 или новее и службы распознавания речи Google с поддержкой вашего языка. Голосовой ввод клавиатуры работает отдельно.", "1c8c24c85e11a338": "Для диктовки на этом устройстве нужны iOS 26 или новее, поддерживаемое устройство и поддерживаемый язык. Диктовка клавиатуры работает отдельно.", + "3dae353469c92182": "Базовый режим использует стандартную речевую модель Google. Расширенный режим использует Gemini Nano на поддерживаемых телефонах и обычно точнее. Голосовой ввод клавиатуры работает отдельно.", + "970e65a607981efa": "Диктовка клавиатуры работает отдельно.", + "0632395d31287ad5": "Распознавание речи Apple на устройстве", + "3606e6ccbe6402a4": "Загружается при первом использовании", + "8da94cf9944b5a42": "Распознавание речи Google на устройстве · {mode} · {language}", + "2757a250104b4b7e": "Расширенный", + "e698e61f5dbb414f": "Базовый", "6e9c96e6b25914bd": "Не удалось сохранить выбор модели расшифровки", "a808542c8c257a51": "Диктовка в окружении отключена для этого сеанса. Сохраните снова перед закрытием приложения, иначе после перезапуска может вернуться прежний выбор.", "88b8883d4b35039b": "Расшифровка недоступна", @@ -3665,6 +3672,7 @@ "5388ec5b413a1243": "Использовать окружение", "67c75c28267889b3": "Способ в {environment}", "13604264948aba9d": "Расшифровывать на", + "2a057e821449a44e": "Это устройство, {engine}", "e3b080ff21a4a1ee": "Звук остаётся на этом устройстве и расшифровывается здесь.", "c6cf6f916fbad786": "Ранее выбранное окружение", "5180a62fd93aac38": "Сопряжение снято", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 3a0273aef36fd..a923b1a80dbdf 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -3608,6 +3608,13 @@ "2638893eacbb570f": "Bilens mikrofon", "2c14a72bd967f644": "Diktering på den här enheten kräver Android 12 eller senare och Googles taltjänster med stöd för ditt språk. Tangentbordets röstinmatning är separat.", "1c8c24c85e11a338": "Diktering på den här enheten kräver iOS 26 eller senare, en enhet som stöds och ett språk som stöds. Tangentbordets diktering är separat.", + "3dae353469c92182": "Grundläggande är Googles vanliga talmodell. Avancerad använder Gemini Nano på telefoner som stöds och är oftast mer träffsäker. Tangentbordets röstinmatning är separat.", + "970e65a607981efa": "Tangentbordets diktering är separat.", + "0632395d31287ad5": "Apples taligenkänning på enheten", + "3606e6ccbe6402a4": "Laddas ner vid första användningen", + "8da94cf9944b5a42": "Googles taligenkänning på enheten · {mode} · {language}", + "2757a250104b4b7e": "Avancerad", + "e698e61f5dbb414f": "Grundläggande", "6e9c96e6b25914bd": "Kunde inte spara transkriberingsvalet", "a808542c8c257a51": "Diktering i en miljö är avstängd för den här sessionen. Spara igen innan du stänger appen, annars kan ditt tidigare val komma tillbaka när den startar om.", "88b8883d4b35039b": "Transkribering är inte tillgänglig", @@ -3617,6 +3624,7 @@ "5388ec5b413a1243": "Använd miljö", "67c75c28267889b3": "Metod på {environment}", "13604264948aba9d": "Transkribera på", + "2a057e821449a44e": "Den här enheten, {engine}", "e3b080ff21a4a1ee": "Ljudet stannar på den här enheten och transkriberas här.", "c6cf6f916fbad786": "Tidigare vald miljö", "5180a62fd93aac38": "Inte längre parkopplad", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index f1c394c60c606..16ff0f2f73375 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -3604,6 +3604,13 @@ "2638893eacbb570f": "车载麦克风", "2c14a72bd967f644": "在此设备上听写需要 Android 12 或更高版本,以及支持你所用语言的 Google 语音服务。键盘的语音输入是单独的功能。", "1c8c24c85e11a338": "在此设备上听写需要 iOS 26 或更高版本、受支持的设备和受支持的语言。键盘的听写是单独的功能。", + "3dae353469c92182": "基础模式使用 Google 的标准语音模型。高级模式在支持的手机上使用 Gemini Nano,通常更准确。键盘的语音输入是独立的。", + "970e65a607981efa": "键盘的听写功能是独立的。", + "0632395d31287ad5": "Apple 设备端语音识别", + "3606e6ccbe6402a4": "首次使用时下载", + "8da94cf9944b5a42": "Google 设备端语音识别 · {mode} · {language}", + "2757a250104b4b7e": "高级", + "e698e61f5dbb414f": "基础", "6e9c96e6b25914bd": "无法保存转写选择", "a808542c8c257a51": "本次使用期间已关闭在环境上听写。请在关闭应用前再次保存,否则应用重启后可能恢复之前的选择。", "88b8883d4b35039b": "转写不可用", @@ -3613,6 +3620,7 @@ "5388ec5b413a1243": "使用环境", "67c75c28267889b3": "{environment} 上的方式", "13604264948aba9d": "转写位置", + "2a057e821449a44e": "此设备,{engine}", "e3b080ff21a4a1ee": "音频保留在此设备上,并在此处转写。", "c6cf6f916fbad786": "之前选择的环境", "5180a62fd93aac38": "已不再配对", diff --git a/apps/mobile/src/lib/permissionStatusAtom.test.ts b/apps/mobile/src/lib/permissionStatusAtom.test.ts index ec3330c8f54aa..b7767fbf15015 100644 --- a/apps/mobile/src/lib/permissionStatusAtom.test.ts +++ b/apps/mobile/src/lib/permissionStatusAtom.test.ts @@ -78,6 +78,9 @@ describe("makePermissionStatusAtom", () => { const { registry, flush } = makeRegistry(); const unmount = registry.mount(atom); + await reads.resolveNext("available"); + registry.refresh(atom); + expect(registry.get(atom)).toBe("available"); for (const listener of native.listeners) listener("active"); await reads.resolveLast("available"); await reads.resolveNext("unavailable"); diff --git a/apps/mobile/src/lib/permissionStatusAtom.ts b/apps/mobile/src/lib/permissionStatusAtom.ts index 0aaded10957f7..94456b85acbc8 100644 --- a/apps/mobile/src/lib/permissionStatusAtom.ts +++ b/apps/mobile/src/lib/permissionStatusAtom.ts @@ -1,3 +1,4 @@ +import { Option } from "effect"; import { Atom } from "effect/reactivity"; import { subscribeAppActive } from "./appState"; @@ -25,7 +26,7 @@ export function makePermissionStatusAtom(options: { }; refresh(); get.addFinalizer(subscribeAppActive(refresh)); - return options.initial; + return Option.getOrElse(get.self(), () => options.initial); }, (ctx, status: S) => ctx.setSelf(status), ).pipe(Atom.withLabel(options.label)); diff --git a/apps/mobile/src/native/voiceTranscription.android.test.ts b/apps/mobile/src/native/voiceTranscription.android.test.ts index e69998f8b15e1..905ae806d001e 100644 --- a/apps/mobile/src/native/voiceTranscription.android.test.ts +++ b/apps/mobile/src/native/voiceTranscription.android.test.ts @@ -1,7 +1,8 @@ import { expect, it, vi } from "vite-plus/test"; const mocks = vi.hoisted(() => ({ - checkAvailability: vi.fn<() => Promise>(), + checkAvailability: + vi.fn<() => Promise<{ language: string; advanced: boolean; downloaded: boolean } | null>>(), prepare: vi.fn<(id: number) => Promise<{ locale: string; mode: number }>>(), transcribe: vi.fn<(id: number, uri: string, locale: string, mode: number) => Promise>(), cancel: vi.fn<(id: number) => Promise>(), @@ -38,11 +39,11 @@ it.each([ expect(createLiveVoiceRecorder()?.uri ?? null).toBe(uri); }); -it.each([false, true])( - "waits for device support before offering a transcriber (%s)", +it.each([null, { language: "English (United States)", advanced: false, downloaded: true }])( + "waits for device support before offering a transcriber (%o)", async (supported) => { vi.resetAllMocks(); - const probe = Promise.withResolvers(); + const probe = Promise.withResolvers(); mocks.checkAvailability.mockReturnValue(probe.promise); let settled = false; const result = Promise.resolve(getLocalVoiceTranscriber()).then((transcriber) => { @@ -52,7 +53,7 @@ it.each([false, true])( await Promise.resolve(); expect(settled).toBe(false); probe.resolve(supported); - expect((await result) !== null).toBe(supported); + expect((await result)?.engine ?? null).toEqual(supported && { kind: "google", ...supported }); }, ); @@ -64,7 +65,11 @@ it.each([ ] as const)("preserves an actionable %s error: %s", async (phase, code, expected) => { vi.resetAllMocks(); resetVoiceInputGlobalsForTests(); - mocks.checkAvailability.mockResolvedValue(true); + mocks.checkAvailability.mockResolvedValue({ + language: "English (United States)", + advanced: false, + downloaded: true, + }); mocks.prepare.mockResolvedValue({ locale: "en-US", mode: 0 }); mocks.transcribe.mockResolvedValue("Complete transcript."); mocks.cancel.mockResolvedValue(undefined); diff --git a/apps/mobile/src/native/voiceTranscription.android.ts b/apps/mobile/src/native/voiceTranscription.android.ts index f596b2a1940e6..091cdd2e689d9 100644 --- a/apps/mobile/src/native/voiceTranscription.android.ts +++ b/apps/mobile/src/native/voiceTranscription.android.ts @@ -8,13 +8,17 @@ import { m } from "../i18n/messages"; import { VoiceTranscriptionError, throwIfVoiceTranscriptionAborted, - type VoiceTranscriber, } from "@t3tools/client-runtime/voice-input"; +import type { LocalVoiceTranscriber } from "./voiceTranscription"; type PreparedGoogleTranscription = { readonly locale: string; readonly mode: number }; type GoogleTranscriptionModule = { - checkAvailability(): Promise; + checkAvailability(): Promise<{ + readonly language: string; + readonly advanced: boolean; + readonly downloaded: boolean; + } | null>; prepare(id: number): Promise; transcribe(id: number, uri: string, locale: string, mode: number): Promise; cancel(id: number): Promise; @@ -51,10 +55,12 @@ export function createLiveVoiceRecorder() { : null; } -export async function getLocalVoiceTranscriber(): Promise { - if (!native || !(await native.checkAvailability())) return null; +export async function getLocalVoiceTranscriber(): Promise { + const support = await native?.checkAvailability(); + if (!native || !support) return null; const module = native; return { + engine: { kind: "google", ...support }, prepare: async ({ signal }) => { const prepared = await runOperation(module, signal, "preparation-failed", (id) => module.prepare(id), diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index e59c6349dfcd4..a79f9ab976ab3 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -9,9 +9,9 @@ import { VoiceTranscriptionError, throwIfVoiceTranscriptionAborted, type PreparedVoiceTranscription, - type VoiceTranscriber, type VoiceTranscriptionOptions, } from "@t3tools/client-runtime/voice-input"; +import type { LocalVoiceTranscriber } from "./voiceTranscription"; const isVoiceTranscriptionError = Schema.is(VoiceTranscriptionError); @@ -46,11 +46,14 @@ function getNativeErrorCode(error: unknown): string | undefined { return typeof error.code === "string" ? error.code : undefined; } -export async function getLocalVoiceTranscriber(): Promise { +export async function getLocalVoiceTranscriber(): Promise { const locales = getPreferredLocales(); // Availability is a device and OS check; which languages have a model only `prepare` knows. if (!AppleTranscription.isAvailable(locales[0]!)) return null; - return { prepare: (options) => prepareVoiceTranscription(locales, options) }; + return { + engine: { kind: "apple" }, + prepare: (options) => prepareVoiceTranscription(locales, options), + }; } async function prepareVoiceTranscription( diff --git a/apps/mobile/src/native/voiceTranscription.ts b/apps/mobile/src/native/voiceTranscription.ts index 496a862836a19..584619c69ee14 100644 --- a/apps/mobile/src/native/voiceTranscription.ts +++ b/apps/mobile/src/native/voiceTranscription.ts @@ -1,5 +1,17 @@ import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; -export async function getLocalVoiceTranscriber(): Promise { +export type LocalVoiceEngine = + | { readonly kind: "apple" } + | { + readonly kind: "google"; + readonly advanced: boolean; + readonly downloaded: boolean; + /** Display name in the device language, from Android: Hermes lacks Intl.DisplayNames. */ + readonly language: string; + }; + +export type LocalVoiceTranscriber = VoiceTranscriber & { readonly engine: LocalVoiceEngine }; + +export async function getLocalVoiceTranscriber(): Promise { return null; } diff --git a/docs/user/composer.md b/docs/user/composer.md index 89a96f120d4d0..9a9c1cc44c83e 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -224,7 +224,10 @@ first time. After that it works offline for that language. iPhone dictates in th first of your preferred languages (**Settings → General → Language & Region**) that Apple’s speech model supports. If none is supported, it tries the app’s language. Android transcribes on the device while you -record and finishes after you stop. Recordings can be up to five +record and finishes after you stop. **Settings → Voice** shows which speech engine +**This device** uses. On Android, **Advanced** uses Gemini Nano on supported phones +and **Basic** is Google’s standard model. This is separate from your keyboard’s +voice typing. Recordings can be up to five minutes long. Canceling or an audio interruption discards the recording and preserves your existing draft. Navigating to another screen keeps dictation active; use the floating controls to finish or cancel. While recording, the screen stays