nimroddolev / chime_tts

A custom Home Assistant integration to play combined audio files before and/or after text-to-speech (TTS) messages
https://nimroddolev.github.io/chime_tts/
MIT License
181 stars 13 forks source link

Feature Request: Parameter for 'Pause'/'Play' media before/after TTS announcement to improve behavior with HomePods #81

Closed jonalbr closed 7 months ago

jonalbr commented 8 months ago

Checklist

Is your feature request related to a problem? Please describe.

Hi, with HomePods, the announce parameter is currently unsupported. But what works great (at least for me) as a workaround is a small script that checks before sending the TTS media if the current state of the media_player/HomePod is “playing”. In that case, it just sends the TTS media as usually but calls service: media_player.media_play right after that, which resumes what was playing before.

Additionally, as I think was already mentioned in a different issue, with HomePods the volume level gets adjusted, before the current media stops. I solve this by calling service: media_player.media_pause before calling chime_tts. However, if I do it, it leaves a rather long period where nothing is played as chime_tts is (as expected) processing a bit before playing. If the 'pause' call were done by chime_tts after processing is complete, it would improve that behavior.

Kind regards, Jonas

Describe the solution you'd like

Add a parameter which, if enabled, does what I described above.

Describe alternatives you've considered

Just continuing using an additional script with chime tts.

Additional context

My script for reference:

alias: ChimeTTS Homepods
fields:
  media_player_entity:
    name: Entity ID of HomePod
    description: Provide entity of HomePod
    example: media_player.arbeitszimmer
    required: true
    selector:
      entity:
        include_entities:
          - media_player.kuche
          - media_player.schlafzimmer
          - media_player.arbeitszimmer
  message:
    name: Message
    description: The message content
    example: Das ist eine Benachrichtigung
    required: true
    selector:
      text: null
  volume_level:
    name: Volume
    description: Set volume level in percent
    example: "35"
    default: 35
    selector:
      number:
        max: 100
        min: 1
        step: 1
        mode: slider
        unit_of_measurement: "%"
sequence:
  - if:
      - condition: template
        value_template: "{{ is_state(media_player_entity, \"playing\") }}"
    then:
      - service: media_player.media_pause
        target:
          entity_id:
            - "{{ media_player_entity }}"
        data: {}
        enabled: true
      - service: chime_tts.say
        data:
          chime_path: bright
          offset: 450
          final_delay: 0
          message: "{{ message }}"
          tts_platform: edge_tts
          language: de-DE-ConradNeural
          volume_level: "{{ volume_level / 100 }}"
        target:
          entity_id: "{{ media_player_entity }}"
      - service: media_player.media_play
        metadata: {}
        data: {}
        target:
          entity_id: "{{ media_player_entity }}"
    else:
      - service: chime_tts.say
        data:
          chime_path: bright
          offset: 450
          final_delay: 0
          message: "{{ message }}"
          tts_platform: edge_tts
          language: de-DE-ConradNeural
          volume_level: "{{ volume_level / 100 }}"
        target:
          entity_id: "{{ media_player_entity }}"
mode: single
JonLaliberte commented 7 months ago

I'd like this a lot 🍻

nimroddolev commented 7 months ago

Thanks for the detailed suggestion @jonalbr.

I will review your workarounds for the announce feature on HomePods and am happy implement it.

nimroddolev commented 7 months ago

Hi @jonalbr and @JonLaliberte,

I just released a new beta version of Chime TTS, v0.13.1-beta3, which adds a new boolean parameter: force_announce

When force_announce is enabled, Chime TTS will simulate the announce feature on unsupported media_player entities (such as the HomePod) so that if music is currently playing, it will be paused before the Chime TTS announcement, and then resumed after it is completed.

Regarding the second issue of the delay, it's beyond the scope of Chime TTS. All Chime TTS-related processing is done before pausing the currently playing audio, and the paused audio is resumed as soon as Chime TTS completes its playback. Therefore any remaining latency is between Home Assistant and the media_player.

I would like to ask you both to please upgrade to the new version and let me know if the new force_announce feature is working for you.

To install the new beta version:

  1. Open the Chime TTS repository in HACS
  2. Click on the button in the top right
  3. Select the ↻ Redownload option
  4. Enable the Show beta versions option (it may take a moment to update the list)
  5. Select version v0.13.1-beta3 from the updated version drop-down list
  6. Restart Home Assistant
jonalbr commented 7 months ago

For me, it is working as expected. Thank you very much!

JonLaliberte commented 7 months ago

Seems to be working well! Thank you!

nimroddolev commented 7 months ago

👍 Good to hear, thank you both for testing. I will include the new feature in the next release.

disruptivepatternmaterial commented 7 months ago

Hey everyone - how are you getting this to work with home pods? I have tried lots of permutations and this is what happens:

1 - the pods jump in volume for a split second 2 - they chime and speak 3 - the media playing doesnt restart and the volume is left on .7 when it was on .3 before

Can someone give me the yaml / screen shot of your entire automation (or the relevant parts)?

THANKS!

jonalbr commented 7 months ago

@disruptivepatternmaterial Are you using the above mentioned beta ? It worked for me to just call the chimetts service with the new force announce (or with beta4 just announce I think) enabled. Than the volume is changed after the pause and is "changed back" after without further configuration

disruptivepatternmaterial commented 7 months ago

@disruptivepatternmaterial Are you using the above mentioned beta ? It worked for me to just call the chimetts service with the new force announce (or with beta4 just announce I think) enabled. Than the volume is changed after the pause and is "changed back" after without further configuration

v0.13.1-beta4

jonalbr commented 7 months ago

One other thing I can think of. The only media I stream is Apple Music directly from the HomePod. What type of media are you streaming? Or more specifically what is the streaming source? Maybe that helps to narrow down the reason for the different behavior.

nimroddolev commented 7 months ago

Hi @disruptivepatternmaterial

1 - the pods jump in volume for a split second 2 - they chime and speak 3 - the media playing doesnt restart and the volume is left on .7 when it was on .3 before

It's not clear from your message what the issue might be. Can you please share your debug log messages?

  1. Turn on debug logging:

    service: logger.set_level
    data:
    custom_components.chime_tts: debug
  2. Call the service chime_tts.say again.

  3. Check your log messages in Home Assistant:

    https://{YOUR_HOME_ASSISTANT_ADDRESS}:8123/config/logs?filter=chime_tts

    and click LOAD FULL LOGS

disruptivepatternmaterial commented 7 months ago

/config/logs?filter=chime_tts

I did as you asked, I am playing music...hit the service (I am working on something that warms me of high winds to take in stuff from the deck) so it says Danger high winds to my HomePods.

And yeah, it stopped the music (after a moment when it got louder) then said the message, then did not resume the music and the volume was left at .7 vs the .3 where I normally listen.

THANKS!!!!

home-assistant_2024-02-15T23-55-22.878Z.log