Wait for TTS audio to finish being played before continuing

Tags: #<Tag:0x00007f326a0575a0>

I use the Text-to-speech component in some of my scripts and automations to send audio messages to my Android TV. It’s working fine for the most part, but in some of my scripts, I’d like the script to wait for the message to finish playing before proceeding with the next action in my sequence - but it seems to consider the action complete as soon as it has successfully sent the audio to the media player. For now, I am using hard-coded delays to work around the issue - but the message is variable-length (weather forecast is part of it) so sometimes I’m waiting unnecessarily and other times, I’m not waiting long enough.

Is there an easy way to know (from within my script) when the audio has finished playing?

Presuming that the media player goes to idle after saying the tts a wait template would work, but you’ll probably need a small delay before the wait template in case the media player is on idle whilst waiting for the tts message to fire.

4 Likes

Yes. I agree with putting a delay in your script.

1 Like

Thanks…. the wait_template worked out. I wasn’t aware that there was such a statement.

I put one wait_template immediately after the tts call that waits until the media_player has a status of ‘playing’, then the script continues, does a few things and then another wait_template that waits for it to switch to ‘idle’ before proceeding with the final few tasks.

2 Likes

You may refer to my post here: Only last service is called?