How to configure Piper as a standard TTS in automations

I am wondering if it is possible to configure Piper as a standard TTS for automations, similar to how you can use cloud.tts. I could have missed examples already posted. Thanks to anyone who can help or point me in the right direction.

I did find a post some where that allowed me to use the current default voice as

speech_engine_offline:
sequence:
- service: media_player.play_media
target:
entity_id: >-
{{ who }}
data:
announce: true
media_content_id: >
media-source://tts/tts.piper?message="{{ message }}"
media_content_type: “music”

But was looking more at something more like

speech_engine_offline:

sequence:

  - service: tts.piper

    data:

      entity_id: >-

        {{ who }}

      message: >-

        {{ message }}

      cache: true

      language: en-GB

      options:

        gender: male

Weird. tts.piper is an entity, not a service.

The service is tts.speak

service: tts.speak
data:
  cache: true
  media_player_entity_id: media_player.esp32_assistant_media_player
  message: Comment allez-vous?
target:
  entity_id: tts.piper

piper / whisper are a bit confusing because they are not integration, either.
The integration is wyoming, and that’s the one providing tts.piper

4 Likes

Ah, thanks Chris.

Thanks folks I appreciate this and will give it a shot. At least it looks like it was not straight forward.
Is there a way to set the voice in the call as well? or are you restricted to the voice set as default?

The docs say you can but give no example: https://www.home-assistant.io/integrations/tts/#service-speak

I had looked there and saw an example in another language of language: “fr” but then it says it has “options” without actually showing how that might look.

Those examples are for the legacy “say” service not the new “speak” service (first section).

I tried with “en” and failed does not seem to be an option, I took a look at the YAML of the default setting in Piper and thought I would give this a shot (didn’t work

speech_engine_offline:

sequence:
  - service: tts.speak
    data:
      cache: true
      media_player_entity_id: '{{ who }}'
      message: '{{ message }}'
      options:
        voice: en-us-kathleen-low

Constructing it using the Developer Tools → Services UI gives this yaml:

service: tts.speak
data:
  message: Testing one two three
  language: en
  options:
    voice: en-us-kathleen-low
  media_player_entity_id: media_player.lounge_speaker
  cache: true
target:
  entity_id: tts.piper

So it looks like you have everything right except the target at the end.

This one was on me as when I checked due to debugging had not included that I already had the target entity (lazy style on my part had it pushed down when trying some things), I am very sorry for that.

speech_engine_offline:
    sequence:
      - service: tts.speak
        data:
          message: '{{ message }}'
          language: en
          options:
             voice: en-us-kathleen-low
          media_player_entity_id: '{{ who }}'
          cache: true
        target:
          entity_id: tts.piper

Did not work for me originally as the en was not recognised. I tried again in dev tools after your suggestion to see if I had botched something which is entirely possible. But it continued to suggest that piper does not recognise it.

I proceeded with the code below:

speech_engine_offline:
    sequence:
      - service: tts.speak
        data:
          message: '{{ message }}'
          options:
            voice: en-us-kathleen-low
          media_player_entity_id: '{{ who }}'
          cache: true
        target:
          entity_id: tts.piper

Without the en reference the script was able to be called however failed to change it from the default voice, giving me the impression that it doesn’t seem yet to be capable of over-riding it with the option

I can’t even get the voice to change in the piper addon. I changed to ryan and restarted the addon but still hear a female voice.

I had to restart HA to get it to. I have another thread talking about being able to even change it in the assistant component. Still very early days in the release yet, so am expecting some of these types of things.

It’s the cache. HA uses a voice recording cache aggressively to reduce processing times. After executing

service: tts.clear_cache

I hear the new voice. Also if I just change my test text.

clearing cache works now for switching of the default. Was holding out hope this might have also been the key to using a non default voice, unfortunately still not able to change it within script.

I’ve asked if the voice option is available over on Discord. Will let you know if I get an answer.

1 Like

Ever got an answer?

Nope.

Is there a character limit on the Piper? I have a rather long “Good Morning” script that plays fine with Google TTS, but Piper stops after a couple sentences. When I run the automation again, it actually picks up on where it left off and continues.

Anyone else experiencing this? The voice quality is unbelievably good! So I want to move completely away from Google TTS.

Edit: Interesting, “en-us-lessac-medium” reads the entire routine.

I have the same phenomenon with a long series of announcements.
I do the different announcements via a separate “service: tts.speak” actions and followed by a delay.

  • delay: ‘00:00:02’
  • wait_template: “{{ is_state(‘media_player.veranda_speaker’, ‘idle’)}}”

When I launch a totally different automation to speak, it indeed often continues with the text of the previous automation.

I did not yet find a solution.