Hi guys,
I have found a solution how to queue TTS speech.
W having some tts messages geting aborted.
With these scripts u only have to update 1 action in all your automations
Keep in mind this is for short messages only <255 characters, i totally forget to mention see msg from 123 Queue TTS automation / Script - #2 by 123
So i decided to find a solution and i found one .
Tutorial: Setting Up a TTS Queue in Home Assistant
Introduction
Setting up a TTS queue in Home Assistant to ensure that your TTS messages are spoken sequentially without overlapping. This setup uses an input text helper to store the queue and scripts to add and process the messages.
Step 1: Set Up the Input Text Helper
- Open Home Assistant.
- Navigate to Settings > Devices & Services > Helpers.
- Click on Add Helper.
- Select Text.
- Name it
tts_queue
.
This helper will be used to store the TTS messages in a queue format.
Step 2: Create the Scripts
Script to Add Messages to the Queue
- Go to Settings > Automations & Scenes > Scripts.
- Click on Add Script.
- Name it
add_to_tts_queue
. - Use the following YAML code:
add_to_tts_queue:
sequence:
- service: input_text.set_value
data:
entity_id: input_text.tts_queue
value: "{{ states('input_text.tts_queue') + ';' + message if states('input_text.tts_queue') else message }}"
- service: script.turn_on
data: {}
target:
entity_id: script.process_tts_queue
This script appends the message to the tts_queue
and triggers the processing script.
Script to Process the TTS Queue
- Go back to Settings > Automations & Scenes > Scripts.
- Click on Add Script.
- Name it
process_tts_queue
. - Use the following YAML code:
process_tts_queue:
sequence:
- repeat:
while:
- condition: template
value_template: "{{ states('input_text.tts_queue') != '' }}"
sequence:
- variables:
messages: "{{ states('input_text.tts_queue').split(';') }}"
message: "{{ messages[0] }}"
- service: tts.google_say # also works with cloud of nabucasa
data:
entity_id: media_player.announcer
message: "{{ message }}"
language: #change it to yours or leave it empty
- service: input_text.set_value
data:
entity_id: input_text.tts_queue
value: "{{ ';'.join(messages[1:]) }}"
- delay: '00:00:10' # Adjust the delay as needed to prevent overlap
This script processes each message in the queue sequentially, with a delay to prevent overlap.
Step 3: Test the Automation
Create an automation to test the TTS queue:
- Go to Settings > Automations & Scenes > Automations.
- Click on Add Automation.
- Set up the following YAML code:
alias: Test TTS Queue test 1
description: ""
trigger: []
condition: []
action:
- service: script.add_to_tts_queue
data:
message: this is a test 5 4 3 2 1 boom
mode: single
alias: Test TTS Queue test 2
description: ""
trigger: []
condition: []
action:
- service: script.add_to_tts_queue
data:
message: Your house is not exploded by the way.
mode: single
Run them both instantly and see it queue! don’t forget to change the delay in the process_tts_queue script!
Explanation
-
add_to_tts_queue
Script:- This script adds the message to the queue stored in
input_text.tts_queue
. - It then triggers the
process_tts_queue
script to ensure the message gets processed.
- This script adds the message to the queue stored in
-
process_tts_queue
Script:- This script processes messages in the queue until it’s empty.
- It uses a delay between messages to prevent them from overlapping.
So if u have multiple TTS automations just change your current to this one
- service: script.add_to_tts_queue
data:
message: {{yout tts speech text]]