Using 'announce' - how to know when it is finished?

I’m experimenting with announce on my Sonos.

But how is it possible to know when the announcement has finished?

None of the media players attributes appear to get updated with the announcement details (e.g. media_duration)

Which makes sense as some kind of black magic is going on presumably the Sonos api is being used to get the announcement to play over the current music.

So knowing when it has finished seems like it might be impossible?

Hi klogg,

I just add a delay after the message is sent and tune it to the message.

I couldn’t determine when the announcement ended, so I calculated a delay based on the message length and words per minute. I used a paragraph with a specific word count and timed my speaker to get its duration.

This is part of my script for notifying and/or speaking through speakers. The delay allows me to repeat messages. It also helps automate other tasks, such as waiting for the message to be spoken before starting music or opening blinds, so the sound doesn’t distract me.

variables:
  tts_wpm: 170
  tts_delay: |-
    {% set word_count = message.split()|length %}
    {{ (word_count / tts_wpm * 60)|round(2) }}
delay:
  hours: 0
  minutes: 0
  seconds: "{{tts_delay}}"
  milliseconds: 0
2 Likes

I love this.
Where did the 170 come from? An estmate?

That’s basically what I did:

  1. Choose a passage of about 200-300 words (with a mix of short and long words, punctuation, etc.).
  2. Run the TTS.
  3. Get the duration of the cache file home assistant created (/config/tts) (But you can easily use a stopwatch or timer function on your phone/computer)
  4. Calculate WPM:
    5. Count the exact number of words in your sample (N).
    6. Note the time taken in seconds (T).
    7. Use this formula: WPM = (N / T) * 60

So for example:
If your 250-word sample takes 100 seconds to speak:
WPM = (250 / 100) * 60 = 150 WPM

It’s not perfect but it does the job quite nicely so far!