SONOS TTS Script

@arsaboo I have two (I believe) simple questions.

Firstly, can you explain why the code posted here which makes perfect sense to me

  - service: tts.google_say
    data_template:
      entity_id: "{{ sonos_entity|default('media_player.livingroomsonos') }}"
      message: "{{ message }}"
  - delay: "{{ delay|default('00:00:00') }}"
  - wait_template: "{{ is_state(sonos_entity|default('media_player.livingroomsonos'), 'playing') }}"
    timeout: '00:00:05'
  - wait_template: "{{ not is_state(sonos_entity|default('media_player.livingroomsonos'), 'playing') }}"
    timeout: '00:02:00'
  - service: media_player.sonos_restore
    data_template:
      entity_id: "{{ sonos_entity|default('media_player.livingroomsonos') }}"

is different from that which you now seem to have on your GitHub which doesn’t seem to me to make sense? Why did you remove the second wait (until it stops playing)?

  - service: tts.google_say
    data_template:
      entity_id: "{{ sonos_entity|default('media_player.livingroomsonos') }}"
      message: "{{ message }}"
  - delay: "{{ delay|default('00:00:00') }}"
  - wait_template: "{{ is_state(sonos_entity|default('media_player.livingroomsonos'), 'playing') }}"
    timeout: '00:00:05'
  - service: media_player.sonos_restore
    data_template:
      entity_id: "{{ sonos_entity|default('media_player.livingroomsonos') }}"

And secondly, I couldn’t find any examples in your repo of you actually calling the script so can you explain how you decide the duration of he delay used in

  - delay: "{{ delay|default('00:00:00') }}"

Thanks.

Is anyone having issues with volume levels with TTS. I find that regardless of what the volume level is set to in my script that my sonos does not really change the volume when speaking. I see the level change in the sonos app, and in the HA entity. But the actual volume of the sound does not change at all. But if I go into the sonos app, set the volume to 100% then run my TTS, it works as expected. I even tried setting the volume to 1 in my automations/scripts, but that does nothing either. If music is playing, same thing, but in those cases the volume of the TTS is so low, you can barely hear it at all. I am using google tts.

Hi,

I am using the very first simple setup proposed and it works fine with one exception.

If the volume (line out level) in Sonos is set to fixed (settings/room settings/(room)/advanced sound/line out level) is set to fixed play does not resume (although everything else I restored correctly). If I set the volume to variable instead of fixed and it works. If I set the volume to fixed again the problem reappears.

I want one specific Sonos unit to be set to fixed for sound quality purposes. Anyone who knows what the problem can be and is there a solution?

Having this problem as well, it’s started to bother the missus :slight_smile: has anyone found a solution to this?

Sonos has no known way to restart a cloud queue so Home Assistant cannot support it. This includes queues started from within Spotify and queues controlled by Amazon Alexa.

EDIT - looks like this hasn’t merged into release yet, I was using dev, so perhaps not helpful (yet, as these changes will be in the next release it looks like)

I was having errors with HA not finding the service as it appears that it has been renamed to drop the media_player part.
In your script try changing the service as such:

media_player.sonos_restore

change to

sonos.restore

okay I think I got it working… But for some reason the audio message sounds twice, I think it has something to do with sonos.restore

Hi All,
I’ve come up with a really great way to do TTS on newer sonos devices using the audioClip functionality in their API: https://developer.sonos.com/code/making-sonos-talk-with-the-audioclip-api/

It reduces the volume of whatever is playing, plays the tts over it, and then brings back the volume. It works perfectly no matter what is playing (cloud queue or not). However, it makes a request to the cloud and only works on newer devices.

I actually have an addon that I’ve written that implements this and it’s been working flawlessly. If there’s any interest, let me know, and I’ll try and get it into a state that I can release.

8 Likes

Definitely interested here.

Alright sweet I’ll try to get it out later today. Just gotta write some documentation on how to get it installed.

2 Likes

Alright all here you go. This is in an ALPHA state but everything should work fine as of today (July 13th, 2019). Please go through the README as configuration is not as simple as most addons. But believe me it’s worth it for the nice TTS experience. This will only work with a newer SONOS device. You can find a link to the full list of devices on the README.

Please let me know of any issues you run into or if you have any questions.

4 Likes

Thanks for this, I’ll definitely give it a try.

Unfortunately as well as some Play:1 devices I also have a Soundbar and an old Play:5 (which I assume is gen 1) so it might not be as suitable for me as I would like.

With is a shame as it sounds like a great solution. Thanks again for doing this.

Ah yes I’m sorry for getting your hopes up. I’ll update my above post to indicate that it only works with the newer devices (its a SONOS api limitation).

No problem…
Are you aware whether there are plans for Sonos to include older devices at a later date?
(Although I am well aware that Sonos always have been very reluctant to disclose any of their plans!!)

Unfortunately no. Though I may be able to get in touch with them and put in a feature request. It might be limited by the available memory on the SONOS device (I believe SONOS loads the entire audioClip into memory before playing instead of streaming it).

A feature request would be better than nothing!
The more I think about this the better it sounds (no pun intended!).

Interesting project, it’d be really interesting to see it as a standalone Sonos tts component. Could you please clarify what " a newer SONOS device" mean? Is there any list of the supported devices, could find it, e.g. Play:1?

I couldn’t find any examples of HA components that had OAuth flows to authenticate against an external service so I decided to implement it as an Addon. If by “standalone” you mean use outside of HA that’s totally possible and there are directions on the README of getting just a standard docker install going.

Currently, the only players that support audio clips are Sonos One, Amp, Play:5 (gen 2), Beam, and the IKEA® SYMFONISK bookshelf and lamp speakers. This page will contain the up to date list if someone comes across this comment in the future: https://developer.sonos.com/reference/control-api/audioclip/

It seems like the SmartThings integration has an OAuth config flow. Anyway, swing by #devs_backend in Discord and you definitely will get help since this is a cool feature.

I’ve decided to leave it as an addon instead of a component for Home Assistant as I saw some interest on Reddit for people running it externally to HA in a container.