Repository navigation
Play announcements on a separate player so music is ducked, not replaced - #67
Open
baileyboy0304 wants to merge 1 commit into
Open
baileyboy0304 wants to merge 1 commit into
baileyboy0304 wants to merge 1 commit into
Conversation
…replaced play-media with announce=true is now played by a new AnnouncementPlayer instead of MusicPlayerService, so the music source, position and play state are kept. It holds transient may-duck audio focus only while speaking; the music player ducks and restores via its focus listener. HA streams TTS WAVs with placeholder 0xFFFFFFFF RIFF/data lengths over chunked HTTP, which ExoPlayer treats as ~12h and never reaches STATE_ENDED. Announcements are downloaded, the WAV lengths corrected and played from a cache file, with a watchdog after the known duration. MusicPlayerService: volume changes received while ducked are no longer discarded (e.g. a volume restore sent during speech), and the ducked flag is cleared when no un-duck animation is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
media_player.play_mediawithannounce: truestops music instead of ducking it. Seen with Music Assistant playing on the VACA media player and an announcement sent to the same entity: the music stops, and Music Assistant's timeline keeps running silently until the music is paused and played again.Two causes:
announce(fixed in Forward announce flag to the device in play_media ViewAssist_Companion_App#329), and everyplay-mediaaction goes toMusicPlayerService.play(url), which swaps the current media item for the TTS clip.0xFFFFFFFFRIFF anddatalengths. ExoPlayer reads that as about 12 h of audio and stays inSTATE_READYafter the speech ends. Example: a 1.46 s clip declareddatasize0xffffffffwith 140,436 actual bytes.Changes
AnnouncementPlayer(new): playsplay-mediawithannounce: trueon its own ExoPlayer.USAGE_NOTIFICATION/CONTENT_TYPE_SPEECH).AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCKonly while speaking, so the music player's existing focus listener ducks and restores the music. Music source, position and play state are untouched, and paused music stays paused.STATE_ENDEDnever arrives.stop()and when a newer announcement replaces it.Satellite.handleMediaPlayerAction: readsannouncefrom the payload and sends the URL to the announcement player or the music player. Without the flag, behaviour is unchanged.MusicPlayerService:setVolume()no longer discards volume changes received while ducked. Previously, a volume restore sent during speech (e.g. after View Assist's listening duck) was lost and music came back at the old ducked level. The new value is now stored and applied when the duck ends.duckedflag is cleared when no un-duck animation is needed (volume already at its target), so it no longer stays set and blocks later volume changes.SatelliteMediaManager: owns the announcement player and stops it instopAll().Testing
Tested on a Facebook Portal+ (Android 10) with Music Assistant playing to the VACA media player. An Echo Dot forwards Assist TTS URLs with
announce: true, with View Assist ducking and a volume restore after the reply:STATE_ENDED(the watchdog did not fire).Not yet tested: music paused before an announcement, failed or cancelled announcements, back-to-back announcements, and
announce: falseregression.Note
On the Portal+, Android ties
STREAM_NOTIFICATIONtoSTREAM_MUSIC, so the Voice and Music volume settings move together. That happens without this change too and isn't addressed here.🤖 Generated with Claude Code