TTS - Errors because it doesn't wait. Is there a way to pause?

Hi.
In our Kitchen tablet we use the HomeAssistant App with (HACS) Kiosk as we use it for multiple purposes while we cook and clean (Plex/Music etc)

I recently installed Fully Kiosk on it in order for it to display a Posterr feed of what we have in Plex when the tablet is locked. I didn’t realise until now that Home Assistant now recognises it as a Media_Player thanks to Fully Kiosk being installed.

So I’ve been setting up a daily greeting as a chain of Google TTS which varies the content depending on who’s in the kitchen and what time of the day it is.
Users have their own toggle that resets when their sleep ends and when the TTS automation runs it turns those off so it won’t keep triggering for them.

The logic in the automation works and each individual TTS speaks correctly when run in isolation, but when run in the full automation sequence it either clips or skips all bar the last sequence.
It also shows an error on the display while clipping/skipping the sections:
“Failed loading sound. Wrong URL or unsupported format?”

If I add a “wait” for n seconds it’ll play for that time before ploughing on to the next even if it isn’t completed.

Is there a way for Home Assistant to detect when the current TTS has completed before continuing with the next step (TTS) in the automation?
If so then I could use a Wait template to hold it on each segment.

Hi callumw,
I know of no way to tell when it stops. I simply add a delay when coding these things in a semi-perm manner. I am often playing am mp3 sound effect plus a TTS and delay: (wait for a time) is plugged between.

I have a TTS script blueprint in my blueprint list in my footer you can look at for inspiration and I have many examples in my config link below as well if you are looking for examples.

You can use the Chime TTS integration which supports queuing sequential service calls to the chime_tts.say service. This means you don’t need to calculate the duration of each TTS message, as it will delay the script until the service call is completed.

hmm… I might give that a go. Thanks for the suggestion

I moved from Google to Piper for their higher quality voices (and local), but my wheezy wee HA server struggles a bit when the text is too long, but I’ll give it a go :slight_smile:

Make the wait_template wait until the media_player’s state value is not equal to playing. You can use also a wait_for_trigger configured to detect a state-change from: playing.

I tried this suggestion just now.
The “playing” state shows immediately, but it takes up to 12s for it to return to the “idle” state.

Worth a try tho

I just had a proper play with Chime TTS.

It does work where you no longer need to add a wait in between TTS messages, however there’s a 5-6s pause between each TTS which is too long for conversational messages.

e.g. I a greeting that changes depending on the time of the day and if a guest is present.
Then a secondary message that give a full weather forecast if before noon and just the temperatures if after.
Then randomly it might TTS a joke.

It would be great if we could have stacked messages and add a short pause (1s) pause between to make it more realistic as the 5s is a bit long.

Odd. I don’t get any delay like that. I play a preamble (an MP3 file) prior to playing a second file (TTS message in WAV format). The second file is played immediately after the first one finishes (no discernible delay between the two).

I use a very short delay (2 seconds, to allow the media_player’s new state to be written to the state-machine) immediately followed by a wait_template to wait until the preamble finishes playing before starting to play the TTS file.

It looks like this (extracted from a larger automation).

## Play preamble
  - service: media_player.play_media
    target:
      entity_id: '{{ new_group_master }}'
    data:
      media_content_id: '{{ preamble }}'
      media_content_type: music

## Wait for preamble to finish playing
  - delay: '00:00:02'
  - wait_template: "{{ states(new_group_master) != 'playing' }}"
    timeout: '00:00:10'

## Play TTS content
  - service: media_player.play_media
    target:
      entity_id: '{{ new_group_master }}'
    data:
      media_content_id: '{{ content }}'
      media_content_type: music