I have a script that speaks various reminders on various media players:
“Its time to let the cats out”
“Its time to feed projectile vomiting dogs white bread”
“Hot tub has reached 102”
Before the TTS plays, I increase the volume of the media player to level 7 for 10 seconds so the TTS can be heard. then I reset it to 4 after TTS where we usually keep it to play background music.
The problem is short sentences get loud background music, long sentences get cut off.
How to calculate the number of seconds it will take to spit out TTS?
Automation:
alias: "Alarm: Cats: Reminder Let Cats out "
description: ""
trigger:
- platform: time
at: "09:45:00"
condition: []
action:
- service: script.alexa_kitchen_play_tts
data:
message: please let the adorable kitty cats out to hunt
mode: single
This automatically adjust the volume for the announcement and then returns it to where it was. This is on a Sonos. Don’t know what you have but give it a try.
That’s how I am doing it. First a little chime on my sonos, then a short wait, then the tts, then the calculated delay length depending on text length - I figured my tts engine speaks at around 150 words per minute
This can also be done with the custom integration Chime TTS.
When calling the chime_tts.say service, you can specify the volume you want for the TTS announcement. It will set the volume, play the announcement, and then reset it once the playback ends.
Well, the Chime TTS doesn’t look like it works on Alexa.
So I got my script working. I had to add 3 seconds to the time function just to pad it. variable names dont seem to like hyphens…
What i did is use the media_duration property of the speaker entity to set a delay after the message was sent, this prevented messages being cut off when a subsequent message command was issued.
Then, in my automations or other scripts I just call the script above with inMediaDevice, and inMessage, here’s an example.
alias: Viking
sequence:
- service: script.custommessagesender
data:
inMediaDevice: media_player.office_mini
inMessage: >-
This is message number 1, and it is a long message. We should wait for
it to finish. In fact, it''s a very long message now, and I wonder how
much this would work.
- service: script.custommessagesender
data:
inMediaDevice: media_player.office_mini
inMessage: This is message number 2.
mode: single
icon: mdi:test-tube