Skip to content

fix: add playback timeout safeguard to AndroidTextToSpeechController#1071

Open
lokhor wants to merge 2 commits into
mainfrom
feature/tts-playback-timeout
Open

fix: add playback timeout safeguard to AndroidTextToSpeechController#1071
lokhor wants to merge 2 commits into
mainfrom
feature/tts-playback-timeout

Conversation

@lokhor
Copy link
Copy Markdown
Collaborator

@lokhor lokhor commented Jun 2, 2026

Problem

When Android TTS drops an onDone/onError callback (audio routing interference, TTS engine glitch, system load), completePlaybackIfDrained() waits forever with non-empty utteranceIdsSpeakingStopped is never emitted and the UI stays stuck on "Speaking response…".

This happens on the Samsung device after wake word → STT → command → TTS starts → callback never fires.

Fix

Added a 30-second safety-net timeout (PLAYBACK_TIMEOUT_MS) in AndroidTextToSpeechController that fires after the final TTS chunk is queued. If utterance callbacks haven't drained all pending utterances by then, it force-cleans the playback state, releases audio focus, and emits SpeakingStopped.

  • speak() / append(isFinal=true) — schedule timeout after final enqueue
  • completePlaybackIfDrained() — cancel timeout on natural completion
  • stop() — cancel timeout on explicit stop
  • Self-cancels if the natural path completes first; emits a Log.w on forced timeout for diagnostics

Testing

  • :core:voice:compileDebugKotlin — passes
  • :core:voice:testDebugUnitTest — all tests pass

…roller

When Android TTS drops an onDone/onError callback (audio routing
interference, engine glitch), completePlaybackIfDrained waits forever
with non-empty utteranceIds and never emits SpeakingStopped, leaving
the UI stuck on 'Speaking response...'.

Add a 30-second safety-net timeout that fires after the final chunk is
queued. If TTS callbacks haven't drained all utterances by then, the
timeout force-cleans the playback state and emits SpeakingStopped.

Cancels automatically on natural completion or explicit stop().
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Debug APK ready

Download app-debug.apk

Commit: 254c910 - Build #2077

Updated on each push. Removed when PR is merged or closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants