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(call-session): improve error reporting and streamline TTS handling

Durganshu Mishra0b7f7a80fdf2
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
index 43f7ab5..5bf802e 100644
--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
@@ -178,11 +178,9 @@ class AssistiveBallService : Service() {
callController.state.collect { state ->
val active = state != CallState.IDLE && state != CallState.ENDING
if (active) {
- overlay.hideChromeForCapture()
chatWindow.show()
} else if (state == CallState.IDLE) {
chatWindow.hide()
- overlay.showChromeAfterCapture()
}
chatWindow.setState(state)
overlay.setCallActive(active)
diff --git a/app/src/main/java/com/gotcha/service/CallSessionController.kt b/app/src/main/java/com/gotcha/service/CallSessionController.kt
index dd0918b..59465e3 100644
--- a/app/src/main/java/com/gotcha/service/CallSessionController.kt
+++ b/app/src/main/java/com/gotcha/service/CallSessionController.kt
@@ -135,7 +135,9 @@ class CallSessionController(
engine = newEngine
_state.value = CallState.STARTING
scope.launch {
- speakText("Call started. I'm ready when you are.")
+ if (!speakText("Call started. I'm ready when you are.")) {
+ reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ }
_state.value = CallState.READY
}
return true
@@ -222,6 +224,12 @@ class CallSessionController(
val text = result.getOrDefault("")
if (text.isBlank()) {
+ // "No speech detected" is a normal outcome, not a config error — only
+ // surface a dialog for actual STT failures (e.g. a bad API key/model).
+ val error = result.exceptionOrNull()
+ if (error != null && error.message != "No speech detected") {
+ reportError(friendlyAgentError(error as? Exception ?: Exception(error.message)))
+ }
_state.value = CallState.READY
return@launch
}
@@ -254,16 +262,17 @@ class CallSessionController(
throw e
} catch (e: Exception) {
val msg = friendlyAgentError(e)
- addTranscript(MessageKind.ERROR, msg)
- onError(msg)
- triggerErrorVibration()
+ reportError(msg)
pendingReply = msg
}
val reply = pendingReply ?: return@launch
_state.value = CallState.SPEAKING
- speakText(reply)
- triggerEndVibration()
+ if (speakText(reply)) {
+ triggerEndVibration()
+ } else {
+ reportError("Couldn't play the voice reply — check your Text-to-Speech settings.")
+ }
onActionRingColor(null)
_state.value = CallState.READY
}
@@ -370,10 +379,7 @@ class CallSessionController(
}
override fun onPermissionRequest(marker: String) {
- val msg = "A permission is needed that can't be granted during a call — open Gotcha to grant it."
- addTranscript(MessageKind.ERROR, msg)
- onError(msg)
- triggerErrorVibration()
+ reportError("A permission is needed that can't be granted during a call — open Gotcha to grant it.")
}
/** The agent asked a question: speak it and wait for a PTT answer. */
@@ -387,7 +393,9 @@ class CallSessionController(
}
}
addTranscript(MessageKind.ASSISTANT, prompt)
- speakText(prompt)
+ if (!speakText(prompt)) {
+ reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ }
val gate = CompletableDeferred<String>()
questionGate = gate
val answer = withTimeoutOrNull(QUESTION_TIMEOUT_MS) { gate.await() } ?: ""
@@ -403,7 +411,9 @@ class CallSessionController(
override suspend fun awaitConfirmation(toolNames: List<String>, description: String): Boolean {
_state.value = CallState.WAITING_USER
addTranscript(MessageKind.ASSISTANT, "Confirmation needed: $description")
- speakText("I need a confirmation — check the dialog on your screen.")
+ if (!speakText("I need a confirmation — check the dialog on your screen.")) {
+ reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ }
val gate = CompletableDeferred<Boolean>()
confirmationOverlay.show(
summary = description,
@@ -422,10 +432,22 @@ class CallSessionController(
_transcript.value = _transcript.value + CallTranscriptItem(nextTranscriptId++, kind, text)
}
- /** Speak with the configured TTS provider; suspends until speech finishes. */
- private suspend fun speakText(text: String) {
+ /** Surface an error the same way everywhere: transcript entry + dialog + haptic. */
+ private fun reportError(message: String) {
+ addTranscript(MessageKind.ERROR, message)
+ onError(message)
+ triggerErrorVibration()
+ }
+
+ /**
+ * Speak with the configured TTS provider; suspends until speech finishes.
+ * Returns false (without reporting — callers decide whether a given
+ * utterance is important enough to surface) if playback failed, e.g. a
+ * misconfigured API TTS provider.
+ */
+ private suspend fun speakText(text: String): Boolean {
val s = settingsRepository.load()
- if (s.ttsProvider == AudioProvider.NONE) return
+ if (s.ttsProvider == AudioProvider.NONE) return true
val voice = if (s.ttsProvider == AudioProvider.API) {
s.ttsVoice.ifBlank {
if (ttsEngine.apiTtsModels.isEmpty()) ttsEngine.refreshApiModels()
@@ -434,7 +456,7 @@ class CallSessionController(
} else {
""
}
- ttsEngine.speak(
+ return ttsEngine.speak(
text = text,
provider = s.ttsProvider,
apiModel = s.ttsApiModel,
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
index a3b3eec..e7e7258 100644
--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
@@ -120,34 +120,37 @@ class AssistiveBallOverlay(context: Context) {
fun canShow(): Boolean =
Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(appContext)
+ /**
+ * Ball/ring/menu (and optionally the error/info card) visibility toggle.
+ * [includeCard] is false for call-active toggling: an error card raised
+ * mid-call must stay visible across the frequent state changes a call
+ * goes through, not flicker in and out with every turn.
+ */
+ private fun setChromeVisible(visible: Boolean, includeCard: Boolean) {
+ val visibility = if (visible) View.VISIBLE else View.INVISIBLE
+ ballView?.visibility = visibility
+ if (visible) ballView?.alpha = PEEK_ALPHA
+ ringView?.visibility = visibility
+ menuView?.visibility = visibility
+ dismissTargetView?.visibility = visibility
+ if (includeCard) cardView?.visibility = visibility
+ }
+
fun hideChromeForCapture() {
- mainHandler.post {
- ballView?.visibility = View.INVISIBLE
- ringView?.visibility = View.INVISIBLE
- menuView?.visibility = View.INVISIBLE
- cardView?.visibility = View.INVISIBLE
- dismissTargetView?.visibility = View.INVISIBLE
- }
+ mainHandler.post { setChromeVisible(visible = false, includeCard = true) }
}
fun showChromeAfterCapture() {
- mainHandler.post {
- ballView?.visibility = View.VISIBLE
- ballView?.alpha = PEEK_ALPHA
- ringView?.visibility = View.VISIBLE
- menuView?.visibility = View.VISIBLE
- cardView?.visibility = View.VISIBLE
- dismissTargetView?.visibility = View.VISIBLE
- }
+ mainHandler.post { setChromeVisible(visible = true, includeCard = true) }
}
fun setCallActive(active: Boolean) {
mainHandler.post {
if (active) {
- hideChromeForCapture()
+ setChromeVisible(visible = false, includeCard = false)
removeMenu()
} else {
- showChromeAfterCapture()
+ setChromeVisible(visible = true, includeCard = false)
}
}
}