fix(tts): fix Android background playback stopping#243
Open
codedogQBY wants to merge 1 commit into
Open
Conversation
Three root causes identified and fixed:
1. Missing Android permissions (app.config.js):
- Add FOREGROUND_SERVICE (parent permission for all foreground services)
- Add WAKE_LOCK (prevents CPU sleep during background audio)
2. ExpoSpeechTTSPlayer unconditionally stops on background:
- The AppState handler called this.stop() on ANY platform going to bg
- Apple's TextToSpeech.framework crashes if active when backgrounded,
but Android handles it fine
- Fix: only stop on iOS, let Android continue playing
3. Silent keep-alive track only enabled on iOS:
- When TTS audio queue starves (network delay between chunks), a 1s
silent track keeps the audio session alive so the OS doesn't reclaim it
- This was iOS-only; Android has the same issue
- Fix: enable on both platforms
Closes #60
Closes #228
Closes #242
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced May 27, 2026
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes TTS audio stopping when Android app goes to background or screen locks. Three root causes:
1. Missing Android permissions
Added
FOREGROUND_SERVICEandWAKE_LOCKto prevent system from killing the audio process.2. ExpoSpeechTTSPlayer stops unconditionally on background
The AppState handler called
this.stop()on all platforms when going to background. This was only needed for iOS (Apple's TextToSpeech crashes if active when backgrounded). Android handles background speech fine.3. Silent keep-alive track only on iOS
When the TTS audio queue starves (network delay between chunks), a 1-second silent track keeps the audio session alive. This was iOS-only but Android has the same need — without it, the system reclaims the audio focus.
Changes
app.config.jsFOREGROUND_SERVICE+WAKE_LOCKpermissionsexpo-speech-player.tsPlatform.OS === "ios"track-player-edge-player.tstrack-player-dashscope-player.tsTest plan
Closes #60
Closes #228
Closes #242
🤖 Generated with Claude Code