Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat(settings): tell app, voice and reply language apart (#74)

Durganshu859c05fd24a1
diff --git a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
index 1796e4d..0d2af09 100644
--- a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
+++ b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
@@ -10,6 +10,7 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.gotcha.data.SettingsRepository
+import com.gotcha.i18n.Language
import com.gotcha.testutil.TestSeed
import org.junit.After
import org.junit.Assert.assertEquals
@@ -93,6 +94,51 @@ class SettingsFlowTest {
assertEquals("No bullet lists.", persisted.userResponseStyle)
}
+ @Test
+ fun languagePage_showsTheThreeLanguagesApartAndPersistsThem() {
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedUnconfigured(context)
+
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+
+ // First run opens on AI Configuration inside the AI hub — two Backs to the list.
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_language_row").performScrollTo().performClick()
+ composeRule.waitForIdle()
+
+ // The point of the page (issue #74): all three named and visible at once.
+ composeRule.onNodeWithText("App display language").assertExists()
+ composeRule.onNodeWithTag("settings_voice_language").performScrollTo().assertExists()
+ composeRule.onNodeWithTag("settings_reply_language").performScrollTo().assertExists()
+
+ // Untouched, the voice follows the reply language — what a pre-#74 install did.
+ composeRule.onNodeWithText("Same as AI reply language").assertExists()
+
+ // The whole point of the split: answers written in one language, spoken in
+ // another. Pick Hindi for the voice and leave the reply language English.
+ composeRule.onNodeWithTag("settings_voice_language").performScrollTo().performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("Hindi").performClick()
+ composeRule.waitForIdle()
+
+ composeRule.onNodeWithTag("settings_save_language").performScrollTo().performClick()
+ composeRule.waitForIdle()
+ scenario?.close()
+
+ // Round-trips through EncryptedSharedPreferences, which no JVM test reaches.
+ val persisted = SettingsRepository(context).load()
+ assertEquals("Hindi", persisted.voiceLanguage)
+ assertEquals("English", persisted.preferredLanguage)
+ // TTS and STT follow the voice; the prompt still follows preferredLanguage.
+ assertEquals(Language.HINDI, persisted.effectiveVoiceLanguage)
+ assertEquals("hi-IN", persisted.effectiveVoiceLanguage.bcp47)
+ assertEquals("hi", persisted.effectiveVoiceLanguage.iso639)
+ }
+
@Test
fun settingsSubPage_opensFromTheListAndBackReturnsToIt() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
diff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
index d8c7c49..c4c7561 100644
--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt
+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
@@ -1362,7 +1362,7 @@ class AgentEngine(
fact("Location", s.userLocation)
fact("Occupation", s.userOccupation)
fact("Background", s.userBackground)
- fact("Preferred language", s.preferredLanguage)
+ fact("Reply language", s.preferredLanguage)
fact("Preferred currency", s.preferredCurrency)
}
return buildString {
diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
index 3546e7d..ab954b0 100644
--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
@@ -864,7 +864,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
ttsEngine.stop()
_uiState.update { it.copy(isSpeaking = true) }
try {
- val language = Language.fromLabel(settings.preferredLanguage)
+ val language = settings.effectiveVoiceLanguage
val defaultVoice = _uiState.value.ttsModels
.firstOrNull { it.id == settings.ttsApiModel }
?.defaultVoiceFor(language) ?: "af_heart"
@@ -925,7 +925,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
)
return
}
- val started = sttEngine.startAndroidListening(Language.fromLabel(settings.preferredLanguage))
+ val started = sttEngine.startAndroidListening(settings.effectiveVoiceLanguage)
if (started) {
_uiState.update { it.copy(isListening = true) }
} else {
@@ -978,7 +978,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
return@launch
}
val sttLanguage = settings.sttLanguage.ifBlank {
- Language.fromLabel(settings.preferredLanguage).iso639
+ settings.effectiveVoiceLanguage.iso639
}
transcript = sttEngine.transcribeApi(
audioFile, settings.sttApiModel, sttLanguage
@@ -999,7 +999,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
// cleanText is redundant there and would cost an extra LLM round-trip.
val cleaned = if (provider == AudioProvider.ANDROID) {
val navModel = settings.navigatorModel.ifEmpty { settings.model }
- client?.cleanText(transcript, navModel, Language.fromLabel(settings.preferredLanguage))
+ client?.cleanText(transcript, navModel, settings.effectiveVoiceLanguage)
?: transcript
} else {
transcript
diff --git a/app/src/main/java/com/gotcha/data/SettingsRepository.kt b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
index bc7c3b6..e16b146 100644
--- a/app/src/main/java/com/gotcha/data/SettingsRepository.kt
+++ b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
@@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import com.gotcha.BuildConfig
import com.gotcha.audio.AudioProvider
+import com.gotcha.i18n.Language
/**
* When the wake-word listener is allowed to run, relative to the screen state.
@@ -170,7 +171,22 @@ data class Settings(
* directive rather than into the profile block.
*/
val userResponseStyle: String = "",
+ /**
+ * The language the assistant *writes* its answers in — the reply directive
+ * and the `<user_profile>` fact in `AgentEngine`. Persisted as a
+ * [com.gotcha.i18n.Language] label; the value must stay stable.
+ */
val preferredLanguage: String = "English",
+ /**
+ * The language speech is spoken and heard in, or blank to follow
+ * [preferredLanguage] — see [effectiveVoiceLanguage].
+ *
+ * Split out from [preferredLanguage] because the two are genuinely separate
+ * choices: plenty of people want answers written in English but read aloud
+ * (and dictated) in their own language. Blank by default so every install
+ * that predates the split keeps behaving exactly as it did.
+ */
+ val voiceLanguage: String = "",
val preferredCurrency: String = "USD",
val communitySkillHosts: Set<String> = setOf(BuildConfig.SAMOSA_SKILL_HOST),
/**
@@ -281,6 +297,14 @@ data class Settings(
else -> ""
}
+ /**
+ * The language TTS speaks and STT listens in: the explicit [voiceLanguage]
+ * when one is set, otherwise the reply language. [sttLanguage] still wins
+ * for transcription specifically, since it is a per-model override.
+ */
+ val effectiveVoiceLanguage: Language
+ get() = Language.fromLabel(voiceLanguage.ifBlank { preferredLanguage })
+
/** True when Samosa AI is selected and a session token exists. */
val isSamosaAuthenticated: Boolean
get() = provider == LlmProvider.SAMOSA_AI && samosaSessionToken.isNotBlank()
@@ -503,6 +527,7 @@ class SettingsRepository(context: Context) : SettingsStore {
userBackground = string(KEY_USER_BACKGROUND),
userResponseStyle = string(KEY_USER_RESPONSE_STYLE),
preferredLanguage = string(KEY_PREFERRED_LANGUAGE, "English"),
+ voiceLanguage = string(KEY_VOICE_LANGUAGE),
preferredCurrency = string(KEY_PREFERRED_CURRENCY, "USD"),
communitySkillHosts = stringSet(KEY_COMMUNITY_SKILL_HOSTS, defaultCommunitySkillHosts),
legalAcceptedVersion = string(KEY_LEGAL_ACCEPTED_VERSION),
@@ -575,6 +600,7 @@ class SettingsRepository(context: Context) : SettingsStore {
.putString(KEY_USER_BACKGROUND, settings.userBackground)
.putString(KEY_USER_RESPONSE_STYLE, settings.userResponseStyle)
.putString(KEY_PREFERRED_LANGUAGE, settings.preferredLanguage)
+ .putString(KEY_VOICE_LANGUAGE, settings.voiceLanguage)
.putString(KEY_PREFERRED_CURRENCY, settings.preferredCurrency)
.putStringSet(KEY_COMMUNITY_SKILL_HOSTS, settings.communitySkillHosts)
.putString(KEY_LEGAL_ACCEPTED_VERSION, settings.legalAcceptedVersion)
@@ -690,6 +716,7 @@ class SettingsRepository(context: Context) : SettingsStore {
const val KEY_USER_BACKGROUND = "user_background"
const val KEY_USER_RESPONSE_STYLE = "user_response_style"
const val KEY_PREFERRED_LANGUAGE = "preferred_language"
+ const val KEY_VOICE_LANGUAGE = "voice_language"
const val KEY_PREFERRED_CURRENCY = "preferred_currency"
const val KEY_COMMUNITY_SKILL_HOSTS = "community_skill_hosts"
const val KEY_LEGAL_ACCEPTED_VERSION = "legal_accepted_version"
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
index fa43223..dd13945 100644
--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
@@ -23,7 +23,6 @@ import com.gotcha.data.ChatHistoryRepository
import com.gotcha.data.SettingsRepository
import com.gotcha.data.WakeWordListeningMode
import com.gotcha.data.settingsChangeNotifier
-import com.gotcha.i18n.Language
import com.gotcha.ui.AssistiveBallOverlay
import com.gotcha.ui.CallChatWindow
import com.gotcha.util.GotchaLog
@@ -807,7 +806,7 @@ class AssistiveBallService : Service() {
screenCompanionPanel.setListening(false)
return
}
- if (sttEngine.startAndroidListening(Language.fromLabel(s.preferredLanguage))) {
+ if (sttEngine.startAndroidListening(s.effectiveVoiceLanguage)) {
panelVoiceActive = true
} else {
overlay.showError("Failed to start speech recognition.")
@@ -861,7 +860,7 @@ class AssistiveBallService : Service() {
}
sttEngine.configureApi(s.effectiveSttBaseUrl, s.effectiveSttApiKey)
scope.launch {
- val sttLanguage = s.sttLanguage.ifBlank { Language.fromLabel(s.preferredLanguage).iso639 }
+ val sttLanguage = s.sttLanguage.ifBlank { s.effectiveVoiceLanguage.iso639 }
val result = sttEngine.stopListeningAndTranscribe(provider, s.sttApiModel, sttLanguage)
screenCompanionPanel.setListening(false)
result
@@ -885,7 +884,7 @@ class AssistiveBallService : Service() {
provider = s.ttsProvider,
apiModel = s.ttsApiModel,
voice = s.ttsVoice,
- language = Language.fromLabel(s.preferredLanguage)
+ language = s.effectiveVoiceLanguage
)
// Playback completed (or was stopped) — reset the speaker icon.
screenCompanionPanel.setSpeaking(false)
diff --git a/app/src/main/java/com/gotcha/service/CallSessionController.kt b/app/src/main/java/com/gotcha/service/CallSessionController.kt
index 0b916a3..21ba322 100644
--- a/app/src/main/java/com/gotcha/service/CallSessionController.kt
+++ b/app/src/main/java/com/gotcha/service/CallSessionController.kt
@@ -213,7 +213,7 @@ class CallSessionController(
narrationErrorReported = false
_state.value = CallState.STARTING
scope.launch {
- val language = Language.fromLabel(s.preferredLanguage)
+ val language = s.effectiveVoiceLanguage
if (!speakText(startGreeting(handsFree, language), language)) {
reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
}
@@ -453,7 +453,7 @@ class CallSessionController(
_state.value = CallState.THINKING
val s = settingsRepository.load()
sttEngine.configureApi(s.effectiveSttBaseUrl, s.effectiveSttApiKey)
- val language = Language.fromLabel(s.preferredLanguage)
+ val language = s.effectiveVoiceLanguage
val sttLanguage = s.sttLanguage.ifBlank { language.iso639 }
val result = sttEngine.stopListeningAndTranscribe(s.sttProvider, s.sttApiModel, sttLanguage)
val text = result.getOrDefault("")
@@ -480,7 +480,7 @@ class CallSessionController(
*/
private suspend fun finishTurn(text: String) {
val s = settingsRepository.load()
- val language = Language.fromLabel(s.preferredLanguage)
+ val language = s.effectiveVoiceLanguage
_state.value = CallState.THINKING
// API STT (Whisper-class) output is already punctuated and cased —
@@ -737,9 +737,9 @@ class CallSessionController(
_transcript.value = _transcript.value + CallTranscriptItem(nextTranscriptId++, kind, text)
}
- /** Resolve the persisted [preferredLanguage] to a [Language]. */
+ /** The language this call is spoken and heard in — see `Settings.effectiveVoiceLanguage`. */
private fun currentLanguage(): Language =
- Language.fromLabel(settingsRepository.load().preferredLanguage)
+ settingsRepository.load().effectiveVoiceLanguage
/** Surface an error the same way everywhere: transcript entry + dialog + haptic. */
private fun reportError(message: String) {
diff --git a/app/src/main/java/com/gotcha/ui/AiHubScreen.kt b/app/src/main/java/com/gotcha/ui/AiHubScreen.kt
index 78a2d66..d941fa1 100644
--- a/app/src/main/java/com/gotcha/ui/AiHubScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/AiHubScreen.kt
@@ -29,7 +29,8 @@ fun AiHubScreen(
SettingsScaffold(title = SettingsPage.AI.title, onBack = onBack, overlay = overlay) {
Text(
"The model does the thinking; speech gives it a voice and ears. " +
- "One provider can cover both.",
+ "One provider can cover both. Which language it speaks and answers " +
+ "in lives under Settings → Language.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
diff --git a/app/src/main/java/com/gotcha/ui/LanguageScreen.kt b/app/src/main/java/com/gotcha/ui/LanguageScreen.kt
new file mode 100644
index 0000000..d72389e
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/LanguageScreen.kt
@@ -0,0 +1,308 @@
+package com.gotcha.ui
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Build
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.material3.Button
+import androidx.compose.material3.DropdownMenuItem
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExposedDropdownMenuBox
+import androidx.compose.material3.ExposedDropdownMenuDefaults
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import com.gotcha.data.Settings
+import com.gotcha.i18n.Language
+import com.gotcha.ui.theme.SkinAlertDialog
+import com.gotcha.ui.theme.SkinExposedDropdownMenu
+import kotlinx.coroutines.launch
+import android.provider.Settings as AndroidSettings
+
+/** Voice-language dropdown entry meaning "no explicit choice — follow the reply language". */
+private const val FOLLOW_REPLY_LANGUAGE = "Same as AI reply language"
+
+/**
+ * The Language page: the three language choices, told apart.
+ *
+ * They used to be scattered and ambiguously named — "Preferred Language" sat in
+ * Personal Info reading like an app-UI setting when it actually drove the LLM
+ * *and* the voice, while "STT Language" sat on the Speech page with no statement
+ * of what it overrode (issue #74). Gathering them here is the only place a user
+ * can see all three at once, which is what makes the difference between them
+ * legible:
+ *
+ * 1. **App display language** — Android's, not ours. The interface is English
+ * only, so this section is honest about that and hands the user off to the
+ * system screen rather than pretending to a picker that would do nothing.
+ * 2. **Voice language** — what TTS speaks and STT listens in
+ * ([Settings.effectiveVoiceLanguage]). Blank follows the reply language.
+ * 3. **AI reply language** — what the model writes in
+ * ([Settings.preferredLanguage]).
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun LanguageScreen(
+ load: () -> Settings,
+ onSave: ((Settings) -> Settings) -> Unit,
+ onBack: () -> Unit,
+ onTestVoice: suspend (Language) -> Boolean? = { null }
+) {
+ val initial = remember { load() }
+ var preferredLanguage by remember { mutableStateOf(initial.preferredLanguage) }
+ var voiceLanguage by remember { mutableStateOf(initial.voiceLanguage) }
+
+ var replyExpanded by remember { mutableStateOf(false) }
+ var voiceExpanded by remember { mutableStateOf(false) }
+ var testingVoice by remember { mutableStateOf(false) }
+
+ /** Last [Language] whose voice data was reported missing, or null when not shown. */
+ var voiceDataMissing by remember { mutableStateOf<Language?>(null) }
+
+ val overlay = rememberSettingsOverlayState()
+ val scope = rememberCoroutineScope()
+ val localContext = LocalContext.current
+
+ /** This page's fields, copied onto [base]. */
+ fun applyLanguages(base: Settings) = base.copy(
+ preferredLanguage = preferredLanguage,
+ voiceLanguage = voiceLanguage
+ )
+
+ /** What the voice would actually use right now, without waiting for a save. */
+ val resolvedVoiceLanguage = Language.fromLabel(voiceLanguage.ifBlank { preferredLanguage })
+
+ SettingsScaffold(title = SettingsPage.LANGUAGE.title, onBack = onBack, overlay = overlay) {
+ Text(
+ "Three separate choices: what the app's own screens are written in, " +
+ "what Gotcha speaks and hears, and what it writes its answers in.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+
+ HorizontalDivider(thickness = 1.dp)
+
+ // ---- 1. App display language ----
+ Text(
+ "App display language",
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.Bold
+ )
+ Text(
+ "Gotcha's own buttons, labels and settings are in English only for now — " +
+ "changing this affects the rest of your phone, not this app.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ OutlinedButton(
+ onClick = { openLanguageSettings(localContext) },
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_open_app_locale")
+ ) { Text("Open Android language settings") }
+
+ HorizontalDivider(thickness = 1.dp)
+
+ // ---- 2. Voice language ----
+ Text(
+ "Voice language",
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.Bold
+ )
+ Text(
+ "What Gotcha speaks aloud and listens for during voice input and calls. " +
+ "Leave it following the reply language unless you want answers written " +
+ "in one language and spoken in another.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ ExposedDropdownMenuBox(
+ expanded = voiceExpanded,
+ onExpandedChange = { voiceExpanded = it }
+ ) {
+ OutlinedTextField(
+ value = voiceLanguage.ifBlank { FOLLOW_REPLY_LANGUAGE },
+ onValueChange = {},
+ readOnly = true,
+ label = { Text("Voice language") },
+ trailingIcon = {
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded = voiceExpanded)
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .menuAnchor()
+ .testTag("settings_voice_language")
+ )
+ SkinExposedDropdownMenu(
+ expanded = voiceExpanded,
+ onDismissRequest = { voiceExpanded = false }
+ ) {
+ DropdownMenuItem(
+ text = { Text(FOLLOW_REPLY_LANGUAGE) },
+ onClick = {
+ voiceLanguage = ""
+ voiceExpanded = false
+ }
+ )
+ Language.labels.forEach { lang ->
+ DropdownMenuItem(
+ text = { Text(lang) },
+ onClick = {
+ voiceLanguage = lang
+ voiceExpanded = false
+ }
+ )
+ }
+ }
+ }
+ Text(
+ "Which voice reads it out is picked per model under Settings → AI → " +
+ "Speech, and the transcription language override on that page wins " +
+ "over this one when it is set.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ OutlinedButton(
+ onClick = {
+ testingVoice = true
+ scope.launch {
+ // Track which language triggered the missing-data state so
+ // rapid language-switch clicks don't surface a stale dialog.
+ val lang = resolvedVoiceLanguage
+ val ok = onTestVoice(lang)
+ voiceDataMissing = if (ok == false) lang else null
+ testingVoice = false
+ }
+ },
+ enabled = !testingVoice,
+ modifier = Modifier.fillMaxWidth()
+ ) {
+ Text(if (testingVoice) "Playing…" else "Test voice")
+ }
+ voiceDataMissing?.let { missingLang ->
+ SkinAlertDialog(
+ onDismissRequest = { voiceDataMissing = null },
+ title = { Text("Voice data not installed") },
+ text = {
+ Text(
+ "Your device doesn't have Android's built-in voice for " +
+ "${missingLang.label}. It was spoken in English instead. " +
+ "Install the voice data to fix pronunciation."
+ )
+ },
+ confirmButton = {
+ Button(
+ onClick = {
+ voiceDataMissing = null
+ try {
+ localContext.startActivity(
+ Intent(
+ android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA
+ ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ )
+ } catch (_: Exception) { }
+ }
+ ) { Text("Install") }
+ },
+ dismissButton = {
+ TextButton(onClick = { voiceDataMissing = null }) { Text("Cancel") }
+ }
+ )
+ }
+
+ HorizontalDivider(thickness = 1.dp)
+
+ // ---- 3. AI reply language ----
+ Text(
+ "AI reply language",
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.Bold
+ )
+ Text(
+ "The language the assistant writes its answers in. Tool names, commands " +
+ "and file paths stay in English so they keep working.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ ExposedDropdownMenuBox(
+ expanded = replyExpanded,
+ onExpandedChange = { replyExpanded = it }
+ ) {
+ OutlinedTextField(
+ value = preferredLanguage,
+ onValueChange = {},
+ readOnly = true,
+ label = { Text("AI reply language") },
+ trailingIcon = {
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded = replyExpanded)
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .menuAnchor()
+ .testTag("settings_reply_language")
+ )
+ SkinExposedDropdownMenu(
+ expanded = replyExpanded,
+ onDismissRequest = { replyExpanded = false }
+ ) {
+ Language.labels.forEach { lang ->
+ DropdownMenuItem(
+ text = { Text(lang) },
+ onClick = {
+ preferredLanguage = lang
+ replyExpanded = false
+ }
+ )
+ }
+ }
+ }
+
+ Button(
+ onClick = {
+ onSave { applyLanguages(it) }
+ overlay.show("Saved language settings.")
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_save_language")
+ ) { Text("Save Language Settings") }
+ }
+}
+
+/**
+ * Open the per-app language screen where the platform has one (API 33+), falling
+ * back to the device-wide language list. Both are ordinary system activities that
+ * a heavily-skinned OEM build may simply not have, hence the catch — the same
+ * shape as the TTS-data launch above.
+ */
+private fun openLanguageSettings(context: android.content.Context) {
+ val intents = buildList {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ add(
+ Intent(AndroidSettings.ACTION_APP_LOCALE_SETTINGS)
+ .setData(Uri.fromParts("package", context.packageName, null))
+ )
+ }
+ add(Intent(AndroidSettings.ACTION_LOCALE_SETTINGS))
+ }
+ for (intent in intents) {
+ try {
+ context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
+ return
+ } catch (_: Exception) { }
+ }
+}
diff --git a/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
index 55a5eb9..b36848e 100644
--- a/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
@@ -8,28 +8,21 @@ import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.gotcha.data.Settings
-import com.gotcha.i18n.Language
-import com.gotcha.ui.theme.SkinAlertDialog
import com.gotcha.ui.theme.SkinExposedDropdownMenu
import com.gotcha.ui.tour.TourAnchor
import com.gotcha.ui.tour.tourAnchor
-import kotlinx.coroutines.launch
/** Currencies offered for [Settings.preferredCurrency]. */
private val CURRENCIES = listOf("USD", "EUR", "GBP", "INR", "CAD", "AUD", "JPY", "CNY")
@@ -42,9 +35,12 @@ private val CURRENCIES = listOf("USD", "EUR", "GBP", "INR", "CAD", "AUD", "JPY",
* language one (see `AgentEngine`). Nothing on this page changes what the agent
* is *allowed* to do; it only changes what it knows about the person asking.
*
- * Language and currency live here rather than under Proactive Assistance, where
- * they started: they describe the user, not whether the assistant volunteers
- * help, and they apply to every reply whether proactive or not.
+ * Currency lives here rather than under Proactive Assistance, where it started:
+ * it describes the user, not whether the assistant volunteers help, and it
+ * applies to every reply whether proactive or not. The language settings used to
+ * sit here too and now have their own page (issue #74) — "Preferred Language"
+ * next to a name and an occupation read as the app's UI language, which it never
+ * was; this page keeps only a pointer to them.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -52,7 +48,7 @@ fun PersonalInfoScreen(
load: () -> Settings,
onSave: ((Settings) -> Settings) -> Unit,
onBack: () -> Unit,
- onTestVoice: suspend (Language) -> Boolean? = { null }
+ onOpenLanguage: () -> Unit = {}
) {
val initial = remember { load() }
var userName by remember { mutableStateOf(initial.userName) }
@@ -60,19 +56,11 @@ fun PersonalInfoScreen(
var userOccupation by remember { mutableStateOf(initial.userOccupation) }
var userBackground by remember { mutableStateOf(initial.userBackground) }
var userResponseStyle by remember { mutableStateOf(initial.userResponseStyle) }
- var preferredLanguage by remember { mutableStateOf(initial.preferredLanguage) }
var preferredCurrency by remember { mutableStateOf(initial.preferredCurrency) }
- var languageExpanded by remember { mutableStateOf(false) }
var currencyExpanded by remember { mutableStateOf(false) }
- var testingVoice by remember { mutableStateOf(false) }
-
- /** Last [Language] whose voice data was reported missing, or null when not shown. */
- var voiceDataMissing by remember { mutableStateOf<Language?>(null) }
val overlay = rememberSettingsOverlayState()
- val scope = rememberCoroutineScope()
- val localContext = LocalContext.current
/** This page's fields, copied onto [base]. */
fun applyPersonalInfo(base: Settings) = base.copy(
@@ -81,7 +69,6 @@ fun PersonalInfoScreen(
userOccupation = userOccupation.trim(),
userBackground = userBackground.trim(),
userResponseStyle = userResponseStyle.trim(),
- preferredLanguage = preferredLanguage,
preferredCurrency = preferredCurrency
)
@@ -174,85 +161,6 @@ fun PersonalInfoScreen(
.testTag("settings_user_response_style")
)
- ExposedDropdownMenuBox(
- expanded = languageExpanded,
- onExpandedChange = { languageExpanded = it }
- ) {
- OutlinedTextField(
- value = preferredLanguage,
- onValueChange = {},
- readOnly = true,
- label = { Text("Preferred Language") },
- trailingIcon = {
- ExposedDropdownMenuDefaults.TrailingIcon(expanded = languageExpanded)
- },
- modifier = Modifier
- .fillMaxWidth()
- .menuAnchor()
- )
- SkinExposedDropdownMenu(
- expanded = languageExpanded,
- onDismissRequest = { languageExpanded = false }
- ) {
- Language.labels.forEach { lang ->
- DropdownMenuItem(
- text = { Text(lang) },
- onClick = {
- preferredLanguage = lang
- languageExpanded = false
- }
- )
- }
- }
- }
- OutlinedButton(
- onClick = {
- testingVoice = true
- scope.launch {
- val lang = Language.fromLabel(preferredLanguage)
- // Track which language triggered the missing-data state so
- // rapid language-switch clicks don't surface a stale dialog.
- val ok = onTestVoice(lang)
- voiceDataMissing = if (ok == false) lang else null
- testingVoice = false
- }
- },
- enabled = !testingVoice,
- modifier = Modifier.fillMaxWidth()
- ) {
- Text(if (testingVoice) "Playing…" else "Test voice")
- }
- voiceDataMissing?.let { missingLang ->
- SkinAlertDialog(
- onDismissRequest = { voiceDataMissing = null },
- title = { Text("Voice data not installed") },
- text = {
- Text(
- "Your device doesn't have Android's built-in voice for " +
- "${missingLang.label}. It was spoken in English instead. " +
- "Install the voice data to fix pronunciation."
- )
- },
- confirmButton = {
- Button(
- onClick = {
- voiceDataMissing = null
- try {
- localContext.startActivity(
- android.content.Intent(
- android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA
- ).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
- )
- } catch (_: Exception) { }
- }
- ) { Text("Install") }
- },
- dismissButton = {
- TextButton(onClick = { voiceDataMissing = null }) { Text("Cancel") }
- }
- )
- }
-
ExposedDropdownMenuBox(
expanded = currencyExpanded,
onExpandedChange = { currencyExpanded = it }
@@ -285,6 +193,21 @@ fun PersonalInfoScreen(
}
}
+ HorizontalDivider(thickness = 1.dp)
+
+ // Language moved out of this page (issue #74); a pointer keeps it findable
+ // for anyone who still comes here looking for "Preferred Language".
+ Text(
+ "Reply, voice and app display language now live on their own page.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ SettingsNavRow(
+ page = SettingsPage.LANGUAGE,
+ onClick = onOpenLanguage,
+ modifier = Modifier.testTag("settings_personal_info_language_row")
+ )
+
Button(
onClick = {
onSave { applyPersonalInfo(it) }
diff --git a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
index abe2171..46e7cf6 100644
--- a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
@@ -15,8 +15,9 @@ import com.gotcha.data.Settings
* The Proactive Assistance page: whether the assistant volunteers help, and
* which surfaces it may scan for the context to do so.
*
- * Language and currency used to live here; they moved to
- * [PersonalInfoScreen] — they describe the user rather than this feature.
+ * Language and currency used to live here; they describe the user rather than
+ * this feature, so currency moved to [PersonalInfoScreen] and language on to
+ * [LanguageScreen].
*/
@Composable
fun ProactiveScreen(
diff --git a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
index 705abf4..dbc0422 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
@@ -101,9 +101,14 @@ enum class SettingsPage(
) {
PERSONAL_INFO(
"Personal Info",
- "Who you are, language, currency, reply style",
+ "Who you are, currency, reply style",
"settings_personal_info_row"
),
+ LANGUAGE(
+ "Language",
+ "App display, voice, and AI reply language",
+ "settings_language_row"
+ ),
AI(
"AI",
"Model, provider, voice and transcription",
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index e5e8e2a..e6205ee 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -120,6 +120,12 @@ fun SettingsScreen(
onApply = onAppearanceChange
)
SettingsPage.PERSONAL_INFO -> PersonalInfoScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onOpenLanguage = { onPageChange(SettingsPage.LANGUAGE) }
+ )
+ SettingsPage.LANGUAGE -> LanguageScreen(
load = load,
onSave = onSave,
onBack = backToHome,
diff --git a/app/src/main/java/com/gotcha/ui/SpeechScreen.kt b/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
index ee62ba8..e3165c9 100644
--- a/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
@@ -456,6 +456,13 @@ fun SpeechScreen(
},
onClearLanguage = { sttLanguage = "" }
)
+ Text(
+ "Leave this empty and transcription follows the voice language " +
+ "set under Settings → Language. Set it to force one language, " +
+ "which helps accuracy when the model tends to guess wrong.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
}
AudioProvider.API -> {
OutlinedTextField(
@@ -508,6 +515,13 @@ fun SpeechScreen(
},
onClearLanguage = { sttLanguage = "" }
)
+ Text(
+ "Leave this empty and transcription follows the voice language " +
+ "set under Settings → Language. Set it to force one language, " +
+ "which helps accuracy when the model tends to guess wrong.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
}
AudioProvider.ANDROID, AudioProvider.NONE -> Unit
}
@@ -729,7 +743,14 @@ private fun SttModelPicker(
}
}
-/** STT language picker — uses the model's languages when available, otherwise [COMMON_STT_LANGUAGES]. */
+/**
+ * Transcription language override — uses the model's languages when available,
+ * otherwise [COMMON_STT_LANGUAGES].
+ *
+ * An override, not the language setting: left empty, transcription follows the
+ * voice language on Settings → Language. It lives here rather than there because
+ * the list of codes it offers comes from the selected STT model (issue #74).
+ */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SttLanguagePicker(
@@ -751,8 +772,8 @@ private fun SttLanguagePicker(
OutlinedTextField(
value = selectedLanguage,
onValueChange = onSelect,
- label = { Text("STT Language (optional)") },
- placeholder = { Text("Auto-detect / Default (or select below)") },
+ label = { Text("Transcription language override") },
+ placeholder = { Text("Follow voice language / auto-detect") },
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded)
},
@@ -763,7 +784,7 @@ private fun SttLanguagePicker(
onDismissRequest = { onExpandedChange(false) }
) {
DropdownMenuItem(
- text = { Text("Auto-detect / Default (empty)") },
+ text = { Text("Follow voice language / auto-detect") },
onClick = onClearLanguage
)
languagesList.forEach { lang ->
diff --git a/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt b/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
index d2a50cb..675d163 100644
--- a/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
+++ b/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
@@ -109,13 +109,26 @@ class AgentPromptTest {
}
@Test
- fun `user profile block carries preferred language and currency facts`() = runTest {
+ fun `user profile block carries reply language and currency facts`() = runTest {
val body = requestBodyFor(AgentMode.OPERATOR)
assertTrue(body.contains("<user_profile>"))
- assertTrue(body.contains("Preferred language: Hindi"))
+ assertTrue(body.contains("Reply language: Hindi"))
assertTrue(body.contains("Preferred currency:"))
}
+ @Test
+ fun `voice language does not affect the written reply language`() = runTest {
+ // Issue #74 split the two: voiceLanguage drives TTS and STT only, so a
+ // German voice must not leak into the directive or the profile block.
+ val body = requestBodyFor(
+ AgentMode.OPERATOR,
+ testSettings { copy(voiceLanguage = "German") }
+ )
+ assertTrue(body.contains("Respond to the user in Hindi"))
+ assertTrue(body.contains("Reply language: Hindi"))
+ assertFalse(body.contains("German"))
+ }
+
@Test
fun `user profile block carries the personal info the user filled in`() = runTest {
val body = requestBodyFor(
diff --git a/app/src/test/java/com/gotcha/data/SettingsTest.kt b/app/src/test/java/com/gotcha/data/SettingsTest.kt
index 876f787..23a6544 100644
--- a/app/src/test/java/com/gotcha/data/SettingsTest.kt
+++ b/app/src/test/java/com/gotcha/data/SettingsTest.kt
@@ -1,6 +1,7 @@
package com.gotcha.data
import com.gotcha.audio.AudioProvider
+import com.gotcha.i18n.Language
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -358,4 +359,28 @@ class SettingsTest {
assertFalse(screenOff.allows(screenInteractive = true))
assertTrue(screenOff.allows(screenInteractive = false))
}
+
+ @Test
+ fun `effectiveVoiceLanguage follows the reply language while voiceLanguage is blank`() {
+ val settings = Settings(preferredLanguage = "Hindi", voiceLanguage = "")
+ assertEquals(Language.HINDI, settings.effectiveVoiceLanguage)
+ }
+
+ @Test
+ fun `effectiveVoiceLanguage prefers an explicit voiceLanguage over the reply language`() {
+ val settings = Settings(preferredLanguage = "Hindi", voiceLanguage = "German")
+ assertEquals(Language.GERMAN, settings.effectiveVoiceLanguage)
+ }
+
+ @Test
+ fun `effectiveVoiceLanguage falls back to English when neither value resolves`() {
+ val settings = Settings(preferredLanguage = "Klingon", voiceLanguage = "Sindarin")
+ assertEquals(Language.ENGLISH, settings.effectiveVoiceLanguage)
+ }
+
+ @Test
+ fun `voiceLanguage defaults to blank so existing installs keep todays behaviour`() {
+ assertEquals("", Settings().voiceLanguage)
+ assertEquals(Language.ENGLISH, Settings().effectiveVoiceLanguage)
+ }
}
diff --git a/app/src/test/java/com/gotcha/i18n/LanguageTest.kt b/app/src/test/java/com/gotcha/i18n/LanguageTest.kt
index 6e9b69d..9e72e34 100644
--- a/app/src/test/java/com/gotcha/i18n/LanguageTest.kt
+++ b/app/src/test/java/com/gotcha/i18n/LanguageTest.kt
@@ -37,8 +37,9 @@ class LanguageTest {
@Test
fun `labels matches the Settings dropdown source of truth`() {
- // Drift guard for design decision D1: the Settings dropdown is derived
- // from Language.labels, so this list is the single source of truth.
+ // Drift guard for design decision D1: both dropdowns on LanguageScreen
+ // (reply language and voice language) are derived from Language.labels,
+ // so this list is the single source of truth.
val expected = listOf(
"English", "Spanish", "French", "German", "Hindi",
"Japanese", "Chinese", "Italian", "Portuguese"