I’m using google’s TTS to announce alarm states (e.g. “arming alarm”, “alarm triggered” etc…)
My sequence always looks like this:
Calling service - set volume 1.0
Calling service - TTS
Calling service - set volume 0.3
I’ve noticed that the volume will drop to 0.3 while my TTS message still playing in the speakers
which forces me to set a wait for x seconds after the TTS step.
Is there any better way to force “wait for sequence to end” before starting the next sequence?
You can wait for the media player’s state to no longer be “playing” (using wait_template or use wait_for_trigger if you want to detect the state-change from “playing” to "idle). This technique waits for the media player to finish (a variable time depending on the length of the content) as opposed to waiting for a fixed time.
Actually a good solution. But as TTS service (I use piper) does not change the status anymore on the media player (I use Sonos), this solution doesn’t work anymore.
There must have been a significant change in the past, as TTS does not interrupt playing music anymore. The music just fades into the background.
That’s because tts.speak and the legacy tts.google_translate_say actually use media_player.play_media and automatically set its announce option to true.
When announce is true, the TTS announcement plays over the existing music. As a result, there’s no change in the media_player’s state (it’s always playing).
If you want the previous behavior, where the existing music is stopped and then the announcement is played, you’ll have to use media_player.play_media directly and set announce to false or simply exclude the announce option (it defaults to false).
What if I want to keep this behavior (TTS announcement over the existing music) and I just want to wait until the announcement is finished. How to handle or wait for this?
When playing a text to speech sequence, I’d like to increase the volume the volume of the media player before and decrease it again after TTS is finished.
Is there any suitable solution to wait for TTS?
PS: There must have been a significant change, as TTS does not interrupt playing music anymore. The music just fades into the background.