🧯 TTS Script Blueprint for All 11 HA Core TTS Flavors

:mega: This is a script that can use any of 11 integrated TTS Platforms Plus Piper via Wyoming Integration in Home Assistant to send a message to a media player. Some will require Google Type Speakers, some will require Non-Google type speakers. This BP can now be called on-the-fly and change the message & media_player when called.

:bookmark_tabs: Changelog

  • 2023-12-07: Stop log spamming leak. #32
  • 2023-09-29: Add the ability to use Piper TTS.
    • Change several of the selectors to allow custom. Use at your own risk.
  • 2023-08-23: Add voice option for the Nabu-Casa tts-cloud.
  • 2023-08-07: Updates for Home Assistant 2023.8
    • Selector syntax change
    • Condition Selector addition (where applicable)
    • MQTT Discovery name changes (where applicable)
    • Clean-up code formatting
  • 2023-07-17: Updated language lists, external links, formatting, & field default.
  • 2023-04-15: Add ability to feed message and media_player change to script on the fly.
  • 2023-03-01: Add Author Tag. Bump HA required Version to 2023-3-0
  • 2022-12-12: Add Update Method Note, minor code change.
    • Name of Blueprint may have changed meaing you have to re-download with a new link.
    • If name changed, it is similar. Variables have not changed.
  • 2022-05-05: Updated for 2022.5.0 HA. Changed Choose to if / then statement.
  • 2022-04-26: Add an optional action selector before and after the main TTS for volume, mp3 sounders, sirens, etc.
  • 2022-04-11: Add multiple to Speaker Selection and changed minimum HA to 2022.4.0
  • 2022-03-09: First blueprint version :tada:

:crystal_ball: About this blueprint

Type of blueprint: SCRIPT

What if I am having problems getting it going?

You can contact me for help, see the links below.

Why do I need this?

This blueprint simplifies the coding required in the Automation/Script calling for a TTS. At that point you only need a service call to run a script to play a pre-planned voice.

The actual mechanics of making the TTS work are in my hands. If HA does an update and breaks it all (again), I will fix the blueprint and you will NOT have to go to 50 places in your yaml code to fix it.

:wrench: Configuration

Requirements

  • Some Version od TTS Installed on your HA instance
  • You know how to deal with TTS messaging

:card_index_dividers: Field variables to feed variables from calling automation

live_message: Live Message
    This will change the default message on-the-fly
    required: false

live_speaker: Live Media Player
    Change the default media player on-the-fly
    required: false

:card_index_dividers: Input fields

b4_action: Action before TTS
    This is intended to add a volume
    control action or whatever you want
    to do before sending the TTS message.

after_action: Action after TTS
    This is intended to add a volume
    control action or whatever you want
    to do after sending the TTS message.

TTS: Text to Speech Processor
    Required on ALL *_say platforms.
    Select the configured TTS engine for
    media_player notifications.
    SEE for details: 
    https://www.home-assistant.io/integrations/#text-to-speech

announcement_message: Spoken Message
    Required on ALL *_say platforms.

speaker_target: Entity(s) to speak thru
    Required on ALL *_say platforms.
    Be sure to select the correct type / brand
    of device for the TTS you are using.
    Not All speakers work with all TTS engines.

speaker_gender: Speaker Gender
    Used on most *_say platforms.
    Select speaker gender male or female.
    May not work with all TTS engines.

baidu_person: Baidu Person Code
    Used only on most tts_baidu_say platform.
    This is the voice code of the speaker.

nabu_azure_language: tts_cloud (Nabu Casa) Language
    Select Language code.
    [See here for Details](https://www.nabucasa.com/config/tts/)

nabu_azure_voice: tts_cloud (Nabu Casa) Voice
    ***Here you need to be careful.***
    If you are OK with the default voice then just leave this field empty.
    If you want to change the voice, you need to pick from [This List, TTS_VOICES section](https://github.com/NabuCasa/hass-nabucasa/blob/master/hass_nabucasa/voice.py)
    being certain to match the country code you picked above with one of
    the voices available for that country code on that list.

cloud_language: TTS Cloud Language
    This is for tts.google_cloud_say.
    See-> https://cloud.google.com/text-to-speech/docs/voices
    NOTE: Not all Language options will have all Genders.

Google_Cloud_Voice: Google Cloud Voice Code
    Used only with tts.google_cloud_say platform. Pick from here-
    https://cloud.google.com/text-to-speech/docs/voices
    This is the voice code of the speaker.
    See-> https://www.home-assistant.io/integrations/google_cloud
    for more information.

Google_Cloud_Profile: Google Cloud Profile
    Used only on most tts.google_cloud_say platform. Pick from here-
    https://cloud.google.com/text-to-speech/docs/audio-profiles
    See-> https://www.home-assistant.io/integrations/google_cloud
    for more information.

GTS_language: TTS Google Translate Say Language
    This is for tts.google_translate_say only. See-> 
    https://cloud.google.com/text-to-speech/docs/voices

marytts_language: Language option for tts.marytts_say
    Used only on tts.marytts_say.

picotts_language: Language option for tts.picotts_say
    Used only on tts.picotts_say.

piper_voice: Voice option for the Piper addon played thru Wyoming
    Used only on Piper.
    [Voice List Here](https://huggingface.co/rhasspy/piper-voices/blob/main/voices.json)
    Also available in the Add-on UI configuration dropdown.
    If a new one is available you can enter it manually.

voicerss_language: Language option for tts.voicerss_say
    Used only on tts.voicerss_say.
    See-> https://www.voicerss.org/api for details.

voicerss_format: Message format option for tts.voicerss_say
    Used only on tts.voicerss_say. See->
    https://www.voicerss.org/api for details.

yandextts_language: Language option for tts.yandextts_say
    Used only on tts.yandextts_say. See->
    https://www.home-assistant.io/integrations/yandextts
    for Details.

yandextts_voice: Voice option for tts.yandextts_say
    Used only on tts.yandextts_say. See->
    https://www.home-assistant.io/integrations/yandextts
    for Details.

yandextts_emotion: Emotion option for tts.yandextts_say
    Used only on tts.yandextts_say. See->
    https://www.home-assistant.io/integrations/yandextts
    for Details.

:eyes: :airplane: Extended Information

The main problem I had with building this blueprint is that I do not have all TTS platforms installed in my system, so there is no way I can test everything. I installed what I could and tested those. Others I just have made available the basic configuration of the tts*_say flavor, speaker entity, and message. If the integration page gave me more specific information, I went with that as options.


I am visioning this as a community project. The Github files are available for forking and PR’s. Also you can post suggestions in the community tab or on my Discord and we can make changes as changes need to be made. I cannot install and pay for all the versions of TTS out there, and I have not covered any of the custom integrations because I simply do not now what there is a demand for.

So if you have ideas and want to help test stuff or want to add some code, let’s have fun!


All constructive help is encouraged.


NOTE: This blueprint replaces 2 other blueprints, so those have been removed from the repository. All the functionality in those has been moved to this one.

  • tts_cloud_message_script.yaml

  • tts_google_translate_say_message_script.yaml

:magic_wand: What TTS Integration Can I use?

These integrations are listed here. Please refer to these pages for care and feeding of the *tts_say method you choose.
:chains: HA TTS Integrations

This blueprint WILL NOT set-up TTS for you. You will be given the opportunity to add the incorrect options that will NOT allow your TTS to function. Your best road to success will be to add a TTS session with UI, and only after that is successfully talking to you should you take the languages and options that work there and apply them in this Blueprint. The safest thing to do other than that is to start with the basic sonfiguration for the TTS_say integration that you are using and add options one at a time after you have it working on a base level.

The very basic requirements are for you to provide the *tts_say method that you have installed and tested, the entity that you want to send it to, and the message you want to send. Beyond that likely involves trial and error that may best be done in the Developer Tools Services area here:

NOTICE: I have added an action statement both before and after the main TTS call. You can choose to ignore these, or you can use them to change volume, add a media player to play a doorbell, turn on a light, add a delay, whatever you want to do.

Open your Home Assistant instance and show your service developer tools.

:fire: This Blueprint makes the assumption that you already have a tested & proven TTS integration installed and you know how it works and how to use it. :fire:

You will need to verify that the name you have given to the TTS integration in your system configuration is the Default name or you need to change this blueprint to use the custom name you have set in the tts: section of configuration.yaml. :end:

:dna: Home Assistant

Once installed, go into blueprints and use this to add a script with your variables. Answer the required questions and you can change or ignore the ones with defaults. Remember the name you typed in. For this example, we will suppose you named the script:
TTS Test One
After that, where ever you want this TTS to sound off in another script or an automation, you simply add a service: (See full examples in my configuration, link below.)

- service: script.tts_test_one

This makes your automation very clean looking and you move all the ‘noisy’ code elsewhere. It has greatly improved my ability to think out automations. This also keeps me from having to write the same code over and over for every TTS I want to send out. I have almost 30 different messages in my Home Assistant Configuration

:woman_cook: Sending TTS messages based on the Calling Automation

As of Version 2021-04-15, thanks to the script Blueprint from Grumblezz I have found a way to feed data into a Script Blueprint. This uses the Key ‘fields:’.
Aside from that, what you need to know is you can use this to generate a ‘live’ TTS response by feeding data into it from an automation that calls this script with data.

To do this, your first step is setting up the Blueprint input fields so that it all works properly with your system. Next you add the input parameters that that you need in order to have the test message coming out of the speaker of your choice. Then save and close the Blueprint Editor. Then you will be able to ‘call’ this script with a data statement that includes the field variables in this section. If you need help formatting the YAML for this you can get some help in the HA Docs here. You can also contact me for help, see the links below.

If you create an automation that calls the script that you created with this BluePrint, you will be able to manually add text or change the speaker. Advanced users will be able to create variables in the automation that can be passed directly to the script to send the TTS message exactly as required.

  - service: script.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaatts_say_testing
    data:
      live_message: |-
        Type something here.
        This is a 2nd line for text. Keep typing for more

:bulb: Fun Ideas

Random Response

This is a very simple sample test case, I wanted to see if it would work. To my delight I have been replacing all the TTS instances in my configuration with blueprints. It puts all the mess in one place. To call a specific message, I just fire the calling script and I have a 1 liner, done.

I have recently found that the !input will accept templates. Who knew, right? I have a few TTS instances that call for a random response, I just need the sound for timing of something I’m doing, and I found that something like this craziness works. It is the lyrics from a song and when triggered, it just picks one of them to play using random. It also picks a random language to speak the message from the list. Pretty slick, right?

Add MP3 File to TTS Call

Here is an example of playing a sound right before the TTS announcement of a doorbell. Below this picture (unseen) is all the TTS answers specific to your selected TTS and such. This picture is of the top part, the ‘Action before TTS’ sample, that you can set-up. In this example the sound file is stored on the media folder so it can be picked from the gui.

These action statements can also be used to change volume, flash a light, turn on a siren, anything you like.

:sun_with_face: :snowflake: Troubleshooting tip

If you are troubleshooting and you want to see more traces back when doing so, here is a TIP I’ve found.
Manually edit the automation created with the ui editor (or manually with a text editor) and add the following to have this automation contain 10 traces instead of the normal 5. Then if the automation is triggering often, you can see the last 10 traces to help you decide what the issue is.
HA Docs on this here.

trace:
  stored_traces: 10

:envelope_with_arrow: Version Updates

Updates will be published on my GIT repository with the rest of my Home Assistant Blueprint collection.

:envelope_with_arrow: There is not an official version control system for Blueprints. However I have found something that comes pretty close. It is not perfect, but for MOST Blueprints, it does just fine. I encourage you to check this script out and use it to easily check if I have updated this blueprint. :link:koter84 Blueprint Update Script

Please Click the :orange_heart: at the end of this top Post if you find this Useful

:calling: Software to Download :floppy_disk:

HA link to download blueprint: Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Direct link to download Blueprint: https://github.com/SirGoodenough/HA_Blueprints/blob/master/Scripts/tts_All_Message_Script_Blueprint.yaml

:globe_with_meridians: All My Blueprints

Link to ALL my Blueprints

https://github.com/SirGoodenough/HA_Blueprints/blob/master/README.md

:man_juggling:t5: Contact Links or see my other work

What are we Fixing Today Homepage / Website: https://www.WhatAreWeFixing.Today/

Channel Link URL: (WhatAreWeFixingToday) https://bit.ly/WhatAreWeFixingTodaysYT

Discord Guild: (Sir_Goodenough#9683) WhatAreWeFixingToday?

:cheese: If you want to support me

Buy me Coffee: https://www.buymeacoffee.com/SirGoodenough

PayPal one-off donation link: PayPal.Me

#WhatAreWeFixingToday

#SirGoodEnough

5 Likes

Perhaps add an option for volume control.

I’ll think about that.
It issue will be because dealing with all TTS means dealing with Alexa and Google and Sonos and Microsoft, I’m betting they don’t all handle it the same. I can only test the Google ones right now. No Alexa hardware. I don’t want to put out something on a guess if I don’t have to.

I was considering moving to the new media selector in the next HA version when they get it fixed. The first release had some problems.

Please click the heart in the top message if you found this useful…

I’m thinking something I could do short term is to add an action sensor that will just do nothing if people don’t need it, but could be used by the user to set-up a volume or flash a light or whatever you want to do. That would work.

Updated as per [MickW69’s suggestion by adding an action sensor before and after the TTS statement.
Use this for volume change or a siren or playing a media file or stacking all 3 in the same action sensor. OR just ignore them and don’t use them at all.

Existing blueprints will work without changes if you want to update to the new version.

Please Click the :orange_heart: at the end of the Top Post if you find this Useful

New Version today.
I did this a couple of days ago but released it today because of the problems with 2033.5.0 and 2022.5.1 releases not allowing Blueprint Imports.

  • 2022-05-05: Updated for 2022.5.0 HA. Changed Choose to if / then statement.

Updated the ‘other blueprints’ links.

November 30, 2022 > Update. Added ZHA Cube Controller version to library.
December 11, 2022 > Update. Added Device Tracker Blueprint to the list.

  • 2022-12-12: Add Update Method Note, minor code change.
    • Name of Blueprint may have changed meaing you have to re-download with a new link.
    • If name changed, it is similar. Variables have not changed.

2024-01-26 added new blueprint

:fire_extinguisher: Zigbee2MQTT Aqara Magic Cube T1-Pro CTP-R01 Xiaomi Lumi cagl02

This Blueprint gives you literally hundreds of actions available on the new Magic Cube.

New Version:

:bookmark_tabs: Changelog

  • 2023-03-01: Add Author Tag. Bump HA required Version to 2023-3-0

New Version:

:bookmark_tabs: Changelog

  • 2023-04-15: Add ability to feed message and media_player change to script on the fly.
1 Like

UPDATE:
2023-08-07: Updates for Home Assistant 2023.8

Selector syntax change

Condition Selector addition (where applicable)

MQTT Discovery name changes (where applicable)

Clean-up code formatting

New Version

:bookmark_tabs: Changelog

  • 2023-08-23: Add voice option for the Nabu-Casa tts-cloud

10-05-2023 NEW VERSION

:bookmark_tabs: Changelog

  • 2023-09-29: Add the ability to use Piper TTS.
    • Change several of the selectors to allow custom. Use at your own risk.

I notice that there was some mention of volume control in the earlier development days. I was wondering if the script perhaps included storing and restoring a volume for a media player for me specifically google homes and the google tts service

I don’t provide code to do that, but I do provide action selectors where you can inject code both before and after the message is sent, so you could add whatever you want in setting volume and grabbing the volume.
This code is available in other places and threads so you can pick what would work best and plug it in yourself.

:bookmark_tabs: Changelog

  • 2023-12-07: Stop log spamming leak. #32

So this touches a few blueprints, but doesn’t change any function. I suggest you use the new re-download feature of Home Assistant, however, and replace them now. Then your logs will be free of the spamming some of the older versions did.