Wait for sequence to finish

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?

Thanks

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.

1 Like

Awesome, thanks for the idea,

1 Like

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.

Is there any other solution to wait for TTS?

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).

I posted an example here:

Ah I get it. Many thanks or the background !!

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?

As explained, the player’s state doesn’t change so you cannot wait for a state-change.

Why do you want to wait for the announcement to finish? Are you using it as a signal to do something?

Referring to a former problem, which is valid again: Wait for sequence to finish

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.

Is this what you are looking for?

    # Wait until media player is stopped
    - wait_template: "{{ is_state('media_player.kitchen_assistant', 'idle') }}"
1 Like