šŸ§Æ 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

  • 2024-06-08: Blueprint Input Sections for enhanced Descriptions.
    • (Documentation change 2-7-2024 to add License notice. Changes only to Descriptions.)
  • 2024-04-21: The gender option for text-to-speech in the Home Assistant Cloud integration is deprecated
  • 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.

:moyai:License Notice:

  • Copies of the original Blueprint that were converted via the ā€˜Take Controlā€™ feature or other means are officially not supported by me.

  • I may or may not be able to support you when you have a problem after you make changes to my code, as some of the code is no longer mine.

  • I & my license also require attribution as a link back to the original should you use this code in your own creation.

  • Here is a link to my license & the original github post expected to be followed & referenced as attribution should you use this code elsewhere.

: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.

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

7 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.

Will this queue TTS messages? i.e. if there are several at once, does the last play over the top or instead of the first few?

HA will send messages sequentially, but a message takes time for the ā€˜speakerā€™ to read.
Therefore you need to add delays to space things out based on how much time the message takes. Thereā€™s no feedback from say google when the TTS has ended, so I donā€™t have a way to automate how long to take. I also donā€™t have the rendered message to determine how much time it needs.

So the answer is yes, but probably not in a useful way.

1 Like

Thanks for that. My other option is to use a series of scripts and automations to append the TTS message to a text helper entity and read from that. Still exploring.

My blueprint has space for action statements before the TTS and after, so if you know the message, you can add the delays right there. Then just call the script with the canned message you sent, and it will delay after the message the time you set so that the message will never be cut-off by another message.

This is how I use this, and also I often send a sound clip with the message by calling the media player blueprint canned sound effect.

ok I saw the pre and post action statement support - can you then pass it a variable delay that I would set when writing the TTS message? So far, all of my messages are written by me rather than from a source that could change length.

I do not have pull in fields for the action statements.
Are the messages always on the fly, or are they the same things over and over. Because for mine that are the same ā€œcannedā€ like 'someone rang the front dootbell" kind of thing, You just use the BP to generate a script for that and you add the words and the action delay or whatever, then you just call the script it makes in your code when you want it to sound.

ok yes I see what you mean.

June 2 2024 NEW VERSION

:bookmark_tabs: Changelog

  • 2024-04-21: The gender option for text-to-speech in the Home Assistant Cloud integration is deprecated

NEW VERSION