SirGoodenough / HA_Blueprints

🧯 My Collection of Automation and Script Blueprints for Home Assistant 🧯
Other
132 stars 22 forks source link

Request to add voice option to door_open_tts_cloud_say_announcer_nabu_casa_required #16

Closed dannymertens closed 1 year ago

dannymertens commented 1 year ago

Hi,

Love the blueprint works great, just a small? Request or I hope it is, I’m not a developer :stuck_out_tongue:

But is it possible to add the voice option, like in the play media service? Creating a setup for my brother and my niece likes this voice for her room, but the parents don’t want to have it as the default voice for the rest of the house :wink:

image

FYI: Language support - Speech service - Azure AI services | Microsoft Learn

Thanks in advance!

Kind regards,

D

SirGoodenough commented 1 year ago

For clarification, this is regarding the Blueprint:

door_open_tts_cloud_say_announcer_nabu_casa_required

So I'm looking at this and it appears possible. However it interferes with gender and language settings. If you pick French and the voice you pick isn't one of the French ones, or you pick a female voice and male is selected, it will error. There is a very long list of voices matched to languages.

https://github.com/NabuCasa/hass-nabucasa/blob/3b9bfe5425206bf91c99d630962df34e2d56fa4e/hass_nabucasa/voice.py#L50-L800

I will look at revamping the entire thing to invoke HA's frontend somehow and have them sort it out. That might work, so I'll keep this open.

Short term look at the blueprint code. This blueprint is just an automation with !inputs replacing the entities and data and such with a bit of added syntax at the start. Convert it back to an automation and do what you will with it. You can also do this and pick a voice that works with your language for you case and have your own version of this BP. I just don't see how I can build the needed logic into existing structure of the BP.

See the added voice: yaml 2 places...


action:
- alias: Repeat the sequence UNTIL the door is closed
  repeat:
    sequence:
    - delay: !input 'cooldown'
    - service: tts.cloud_say
      data:
        entity_id: !input 'speaker_target'
        message: !input 'announcement_message'
        options:
          gender: !input 'speaker_gender'
          voice: ChristopherNeural
        language: !input 'speaker_language'
    until:
    - condition: state
      entity_id: !input 'door_entity'
      state: 'off'
- service: tts.cloud_say
  data:
    entity_id: !input 'speaker_target'
    message: !input 'final_message'
    options:
      gender: !input 'speaker_gender'
      voice: ChristopherNeural
    language: !input 'speaker_language'

You can edit that like it is in the BP, or pull the actions out, plug it into an automation as the action statement, and replace the !input statements with real values to make a local automation. (Pick a voice from the list that matches the language and gender you are looking for, of course.)

SirGoodenough commented 1 year ago

Doing some fun testing... Randomice the voice for all the en-US

action:
- alias: Repeat the sequence UNTIL the door is closed
  repeat:
    sequence:
    - delay: !input 'cooldown'
    - service: tts.cloud_say
      data:
        entity_id: !input 'speaker_target'
        message: !input 'announcement_message'
        options:
          gender: !input 'speaker_gender'
          voice: >-
            {{ (
              "JennyNeural",
              "AIGenerate1Neural",
              "AIGenerate2Neural",
              "AmberNeural",
              "AnaNeural",
              "AriaNeural",
              "AshleyNeural",
              "BrandonNeural",
              "ChristopherNeural",
              "CoraNeural",
              "DavisNeural",
              "ElizabethNeural",
              "EricNeural",
              "GuyNeural",
              "JacobNeural",
              "JaneNeural",
              "JasonNeural",
              "JennyMultilingualNeural",
              "MichelleNeural",
              "MonicaNeural",
              "NancyNeural",
              "RogerNeural",
              "SaraNeural",
              "SteffanNeural",
              "TonyNeural"
            ) | random }}
        language: !input 'speaker_language'
    until:
    - condition: state
      entity_id: !input 'door_entity'
      state: 'off'
- service: tts.cloud_say
  data:
    entity_id: !input 'speaker_target'
    message: !input 'final_message'
    options:
      gender: !input 'speaker_gender'
      voice: >-
        {{ (
          "JennyNeural",
          "AIGenerate1Neural",
          "AIGenerate2Neural",
          "AmberNeural",
          "AnaNeural",
          "AriaNeural",
          "AshleyNeural",
          "BrandonNeural",
          "ChristopherNeural",
          "CoraNeural",
          "DavisNeural",
          "ElizabethNeural",
          "EricNeural",
          "GuyNeural",
          "JacobNeural",
          "JaneNeural",
          "JasonNeural",
          "JennyMultilingualNeural",
          "MichelleNeural",
          "MonicaNeural",
          "NancyNeural",
          "RogerNeural",
          "SaraNeural",
          "SteffanNeural",
          "TonyNeural"
        ) | random }}
    language: !input 'speaker_language'

Also going to look at getting the close message immediately, instead of after the delay.

SirGoodenough commented 1 year ago

I have a version to try. @dannymertens Load it up and let me know what you think.

https://github.com/SirGoodenough/HA_Blueprints/blob/TTS-Voice/Automations/door_open_tts_cloud_say_announcer_nabu_casa_required.yaml

dannymertens commented 1 year ago

I have a version to try. @dannymertens Load it up and let me know what you think.

https://github.com/SirGoodenough/HA_Blueprints/blob/TTS-Voice/Automations/door_open_tts_cloud_say_announcer_nabu_casa_required.yaml

Works perfect, thanks!!!

dannymertens commented 1 year ago

What also would be cool, maybe something for a future update?

Now the message after the cooldown time is always the same, maybe if possible add a second, third message option? That way you can for instance make the second, third message a bit more lets say directer, you know kids :-)

Just an idea... very happy with the extra voice option!

Thanks!

SirGoodenough commented 1 year ago

Did you notice the close message is now just a few seconds after thew door closes, instead of waiting for the delay to complete?

This was the first BP I ever wrote, and it was 99% a copy of another one. I've learned a bit since...

SirGoodenough commented 1 year ago

If you want different messages to come up, do the same thing I suggested for the voice (in the description of the input), but put different messages in there. I'm probably not going to edit the BP for that because this option exists.