Using tts.google_say with Sonos speaker on hass.io

So, I have a set of sonos speakers and I really just want to be able to make them say things using the tts.google_say functionality. Similar to the example found here:

service: tts.google_say
entity_id: media_player.sonos_speaker
data:
  message: 'May the Force be with you.'

However, when I try to fire an event like this to my speaker:

  1. it appears as though the tts function works, an mp3 file gets created in the tts folder with a long hash-code filename.
  2. I have the Sonos application open when I do that and I can see the speaker’s playlist change to the long hash code string it sits like this for a few seconds trying to play, then it displays an “unable to play [filename.mp3], unable to connect to [my url]” message.

I’m using duckdns and I’ve found that I can navigate to these two urls and play the mp3s in a browser from a computer on my network:
https://xxxxx.duckdns.org/api/tts_proxy/14046a118657360146fa85207615cc5486df7771_en_-_google.mp3
https://xxxxx.duckdns.org/local/audio/stuff.mp3

I copied the hash-code named mp3 file into /config/www/audio/stuff.mp3 and it works there too.

Then, get this: I actually used the event fire service to launch those files into the Sonos speaker manually and it worked!

Service: media_player.play_media
Entity: media_player.sonos_speaker
Service Data:
{
  "entity_id": "media_player.office_sonos",
 "media_content_id": "https://xxxxx.duckdns.org/api/tts_proxy/14046a118657360146fa85207615cc5486df7771_en_-_google.mp3",
 "media_content_type": "audio/mp4"
}

To my surprise, this works great! I can also use the /local/audio/stuff.mp3 link and it works. So, the question is now, why doesn’t the tts.google_say service call send the same kind of execution instruction as the media_player.play_media function? Clearly the Sonos speaker can play the tts stuff but it doesn’t do it natively. How can I get this to work more seamlessly?

1 Like

Have you looked at this? It works perfectly for me. Have started with this and expanded with several standard texts through input template.

1 Like

TTS actually does call media_player.play_media.

Are you sure it’s the same URL? Did you set base_url in the configuration?

Yes I have base url under HTTP in my configuration.yaml and haven’t had any issues. If you post your configuration.yaml I might be able to potentially see any difference.

I think I just figured it out! Unfortunately, I have not been able to find a way to look at the entire URL that is getting sent to the Sonos speaker when I fire off the say.google_tts event. The best I get is a short-lived popup message from the Sonos app about “unable to play” without a full URL, like this:
image
When I captured that screen shot I realized that it was trying to hit the server at port 8123! Probably because I’m using these things in configuration.yaml:

http:
  base_url: https://xxxxx.duckdns.org:8123
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

tts:
  - platform: google

I didn’t have anything else under tts:. I added a new base_url: http://xxxx.duckdns.org without the port listing and that solved the problem of using say.google_tts!!

I haven’t seen that script yet, thanks for sharing it, it’s pretty awesome! Now, I need to template a bunch of stuff in my house with this. Any pointers or suggestions? I’ve recently added a bunch of door, window, moisture, motion sensors so I’m thinking I’ll probably template a bunch of those things to make the speaker tell me what’s going on.

Thanks for the help guys!

Quick question, do you guys have any way to leave the playing queue undisturbed while making an announcement through the speakers? After running an event that causes an announcement through the speaker the playing queue has only that last announcement. I see from the Sonos component page that the snapshot/restore doesn’t handle the playing queue but is there any other way to do that?

I posted my config and template here:

If you are using media_player.sonos_unjoin, that can break things. There are fixes for that in version 0.90 (currently available as beta).