Help with TTS reading from a .yaml file (Google Cloud)

Hey, hoping someone can help me here.

I use Google Cloud as my text to speech service in Home Assistant. Everything works fine calling the service within an automation/script. However these TTS messages have grown in size quite a bit over time and I would like to move the message to a yaml file that the TTS can read from.

I have seen some videos online where in the message section of the TTS service they use ‘!include path/to/yaml/file.yaml’. But any time I enter this in an automation/script either via the front end or in yaml, Google always just reads the message as is ( example “!include path/to/yaml/file.yaml”) instead of the content that is in the yaml file.

Where am I going wrong with this? Is there something I need to input into my configuration.yaml file or how can I get the TTS service to read from a yaml file instead of having to put the message directly in the automation/script?

service: tts.google_cloud_say
data:
  cache: true
  entity_id: media_player.googlehomemini
  options:
    text_type: ssml
  message: <speak> '!include /config/text_to_speech/welcome_home.yaml' </speak>

Example welcome_home yaml file

>
  {{ [ "Welcome home",
  "Good to see you again",
  "Home sweet home"
  ] | random }}

Cheers

No idea. Show us how you are attempting to use it.

Thanks Tom. I’ve updated the original posting now

Saw this elsewhere in the forum.

You have to move all the text to your include file, including the <speak> tags. Then you just use this:

message: !include /config/text_to_speech/welcome_home.yaml

Thanks for that link. It pointed me in the right direction and I finally got it working.

It seems a bit counterintuitive to set a variable with the TTS message first but seems to work. Now to test with a longer message and hopefully it still work. Not sure how many characters you can store in the variable so hopefully it doesn’t fall over with longer messages.

For anyone looking at this in the future don’t include the in the message part of the TTS service but do include it in the yaml file otherwise it won’t work. This only applies if you are using Google Cloud Say and not the regular TTS service from Google.

Hi @unknowndarkmatterpie
Having the same troubles here with getting the path spoken instead of the file content I’m pointing to. Would you mind to post your service call and your yaml-file content?

Sure, what I did was create a script and in the sequence I would first define a variable which would grab the TTS message from a yaml file (using the !include path) and then next step in the sequence I would call the TTS service and instead of passing it the path the yaml file, I would just pass it the variable.
Example below:

 sequence:
    - variables:
        announcement:  !include /config/text_to_speech/welcome_home.yaml # path to your yaml file which contains the TTS message
    - service: tts.google_cloud_say
      data:
        cache: false
        entity_id: media_player.googlehomemini
        options:
          text_type: ssml
        message: "{{ announcement }}"

Thank you @unknowndarkmatterpie for that. For some reason when I copy your sequence posted the script editor does not accept the announcement variable. Any hint for that?

Did you change the path to where your text to speech file exists?

sequence:
  - variables:
      announcement:  !include /config/tts/andy/test.yaml
  - service: tts.google_de_ch
    data:
      cache: false
      entity_id: media_player.buro
      options:
        text_type: ssml
      message: "{{ announcement }}"

When ttying to save in the script editor it says the following
“Message malformed: Integration ‘’ not found”

As soon as I delete the “!include” it lets me save it. What am I missing here…?