The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): Android dictation works with regional preferences set (#31030)
Md Ehsanul Haque committed
Nov 6, 2026 at 06:48 UTC
b39d0f2fccc7bad262528fdf10f326648823fe2f
3 files changed
+19
-2
apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriber.kt
+4
@@ -22,6 +22,10 @@ internal class VoiceTranscriptionException(
22
cause: Throwable? = null
23
) : Exception(message, cause)
24
25
+// ML Kit reports every mode UNAVAILABLE for tags with Unicode extensions, which Android adds
26
+// for regional preferences such as the temperature unit (en-US-u-mu-celsius).
27
+internal fun speechLocale(systemLocale: Locale): Locale = systemLocale.stripExtensions()
28
+
29
private val recognitionModes = listOf(
30
SpeechRecognizerOptions.Mode.MODE_ADVANCED,
31
SpeechRecognizerOptions.Mode.MODE_BASIC
apps/mobile/modules/t3-voice-transcription/android/src/main/java/expo/modules/t3voicetranscription/T3VoiceTranscriptionModule.kt
+2
-2
@@ -37,7 +37,7 @@ class T3VoiceTranscriptionModule : Module() {
37
} else {
38
withContext(Dispatchers.IO) {
39
val context = requireNotNull(appContext.reactContext)
40
- val locale = Resources.getSystem().configuration.locales[0]
40
+ val locale = speechLocale(Resources.getSystem().configuration.locales[0])
41
isGoogleVoiceTranscriptionSupported { MlKitSpeechClient(context, locale, it) }
42
}
43
}
@@ -52,7 +52,7 @@ class T3VoiceTranscriptionModule : Module() {
52
)
53
}
54
val context = requireNotNull(appContext.reactContext)
55
- val locale = Resources.getSystem().configuration.locales[0]
55
+ val locale = speechLocale(Resources.getSystem().configuration.locales[0])
56
val mode = prepareGoogleVoiceTranscription { MlKitSpeechClient(context, locale, it) }
57
mapOf("locale" to locale.toLanguageTag(), "mode" to mode)
58
}
apps/mobile/modules/t3-voice-transcription/android/src/test/java/expo/modules/t3voicetranscription/GoogleVoiceTranscriberTest.kt
+13
@@ -4,6 +4,7 @@ import com.google.mlkit.genai.common.FeatureStatus
4
import com.google.mlkit.genai.common.GenAiException
5
import com.google.mlkit.genai.speechrecognition.SpeechRecognizerOptions
6
import com.google.mlkit.genai.speechrecognition.SpeechRecognizerResponse
7
+import java.util.Locale
8
import kotlinx.coroutines.CompletableDeferred
9
import kotlinx.coroutines.cancelAndJoin
10
import kotlinx.coroutines.flow.flow
@@ -14,6 +15,18 @@ import org.junit.Assert.assertTrue
15
import org.junit.Test
16
17
class GoogleVoiceTranscriberTest {
18
+ @Test
19
+ fun dropsRegionalPreferenceExtensionsFromTheSpeechLocale() {
20
+ for ((system, expected) in listOf(
21
+ "en-US-u-mu-celsius" to "en-US",
22
+ "en-GB-u-fw-mon-mu-celsius" to "en-GB",
23
+ "ar-EG-u-nu-latn" to "ar-EG",
24
+ "zh-Hant-TW" to "zh-Hant-TW"
25
+ )) {
26
+ assertEquals(expected, speechLocale(Locale.forLanguageTag(system)).toLanguageTag())
27
+ }
28
+ }
29
+
30
@Test
31
fun preservesUtterancesAndTheirSpacingWithoutDuplicatingHypotheses() = runBlocking {
32
for ((finals, trailing, expected) in listOf(