Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonos media.player TTS announcement "echos" when targeting two speakers #93136

Closed
snarlingllama opened this issue May 16, 2023 · 7 comments
Closed
Assignees

Comments

@snarlingllama
Copy link

snarlingllama commented May 16, 2023

The problem

I know there has been an update in core for this integration that allows the music to not be stopped during an announcement. The side effect is that TTS audio no longer plays to the Sonos grouped speakers; only the targeted speaker.

The main issue I am having is that when I manually add other target Sonos speakers, the audio does not playback at the same time in sync and gives a very unpleasant "echo" effect. Its not a true echo, but rather the fact that the TTS audio does not play in sync like the used to when it honored Sonos groups.

Is there anyway around this and/or could there be additional features added to allow TTS audio to play via the old group feature? The echo effect is so bad it makes understanding the TTS message difficult.

What version of Home Assistant Core has the issue?

core-2023.5.3

What was the last working version of Home Assistant Core?

core-2023.4.6

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Sonos

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sonos/

Diagnostics information

No response

Example YAML snippet

alias: "Notification: Lightning Strike"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.blitzortung_lightning_counter
    not_from:
      - unknown
      - unavailable
    not_to:
      - "0"
      - unknown
      - unavailable
condition:
  - condition: template
    value_template: |2-
        {{ as_timestamp(now()) - as_timestamp(state_attr(this.entity_id,
          'last_triggered')) | int(0) > 10800 }}
action:
  - service: media_player.play_media
    data:
      media_content_type: music
      media_content_id: http://<IP>:8123/local/audio/lightning-notification-chime.mp3
    target:
      entity_id:
        - media_player.sonos_bedroom
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 500
  - service: tts.google_translate_say
    entity_id:
      - media_player.sonos_bedroom
    data_template:
      message: >
        '"Attention! A lightning strike has been detected {{
        states('sensor.blitzortung_lightning_distance') }} kilometers
        from your location."'
mode: single

Anything in the logs that might be useful for us?

No response

Additional information

Using Sonos One SL speakers if it matters.

@home-assistant
Copy link

Hey there @cgtobi, @jjlawren, mind taking a look at this issue as it has been labeled with an integration (sonos) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of sonos can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign sonos Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


sonos documentation
sonos source
(message by IssueLinks)

@jjlawren
Copy link
Contributor

Yes, similar to the example of passing the volume option along with the announce parameter to TTS, you can use a media source URL to disable announce functionality:

service: media_player.play_media
target:
  entity_id: media_player.sonos
data:
  announce: false
  media_content_id: >
    media-source://tts/google_translate?message="I am not using announce"
  media_content_type: "music"

@geekofweek
Copy link
Contributor

Seems to be a lot of issues getting opened, and closed, around this. It appears to be a much larger breaking change than was originally identified since previous functionality behaves differently and breaks what was working, including the original (old) published Sonos examples. I did a lot of trial and error having the same problems with it either only targeting one member of the Sonos group, or if targeting all members of the group individually the audio being out of sync (ignoring the group).

the two conclusions I came to are:

  • setting announce: false only works if the Sonos are in a group prior to the TTS message being sent
  • If announce: false is set it ignores the volume option, you have to set the volume prior with media_player.volume_set

I have some working examples here using the old method of Sonos snapshot, un-join, join, set volume, play TTS, Sonos restore. I was hopeful the announce function would simplify that, but the out of sync audio is just too much to handle.

@jjlawren
Copy link
Contributor

the two conclusions I came to are:

  • setting announce: false only works if the Sonos are in a group prior to the TTS message being sent
  • If announce: false is set it ignores the volume option, you have to set the volume prior with media_player.volume_set

You're describing how all media_player.play_media and TTS calls worked previous to 2023.5. The new codepath is only used when announce: true is set, otherwise it falls back to the legacy behavior.

The benefits of the new announce behavior:

  • It avoids the need for very complex snapshot/restore/volume_set/group/etc scripts & automations. You simply make the announcement without having to to care about the current state of the speaker.
  • It does not interrupt music, which is important for some services (e.g. Spotify) which cannot resume from a snapshot.

The downsides:

  • It targets individual speakers and not groups, so audio is not perfectly synced.
  • The speaker does not report back when an announcement has completed, which makes chaining multiple announcements together difficult.

The downsides are limitations in the new API and workarounds are not likely. Unless Sonos improves this API or provides a new one, you'll need to decide which behaviors are more important to you.

@geekofweek
Copy link
Contributor

I think the problem stems from that using media_player.play_media and tts_cloud.say prior to 2023.5 behaved differently.

So even in 2023.5 and not calling announce:true doesn't work the same way

Example:

    - service: media_player.join
      data:
        entity_id:
          - media_player.sonos_test_room
        group_members:
          - media_player.sonos_test_room_2
          - media_player.sonos_test_room_3
    - service: tts.cloud_say
      data_template:
        entity_id: media_player.sonos_test_room
        message: 'Test Message'

This will only play the message on media_player.sonos_test_room, prior to 2023.5 this would have played to the entire group.

To mimic the same (synced audio to a group) behavior you can no longer use the tts service calls you must use media_player.play_media with announce: false . That also means that pre-existing tts based automations will no longer really work the same even if not specifically calling announce: true.

There was a change to how the functionality behaves, I'm just highlighting what needs to happen to get it like for like (synced audio to a group) how it worked prior to 2023.5.

@jjlawren
Copy link
Contributor

You're correct. The tts.*_say services have sent the announce option under the hood since announce was added, but it was silently ignored (in Sonos and probably most media_player integrations) as there wasn't support for it yet.

@snarlingllama
Copy link
Author

snarlingllama commented May 21, 2023

Yes, similar to the example of passing the volume option along with the announce parameter to TTS, you can use a media source URL to disable announce functionality:

service: media_player.play_media
target:
  entity_id: media_player.sonos
data:
  announce: false
  media_content_id: >
    media-source://tts/google_translate?message="I am not using announce"
  media_content_type: "music"

Thank you for this! I was able to get my automations to play TTS in sync through my grouped Sonos speakers with this.

What is syntax for the media-source://tts if I wanted to use Piper instead? I tried the following options, but TTS didn't work:

media-source://tts/tts.speak?message="I am not using announce"

media-source://tts/speak?message="I am not using announce"

media-source://tts/tts.piper?message="I am not using announce"

UPDATE:

Must have just need a few minutes to figure itself out. I was able to get it to work with:

media-source://tts/tts.piper?message="I am not using announce"

@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants