Notification are automatically managed by the application. It will return playback once the notification has played. Either play a mp3 or a spoken message.
Play a mp3
To play a short music file as a notification send the following payload to command topic. You can send multiple notifications after each other, and they will be played after each other.
There is a second implementation of the notification queue, that you can use with the following command. You should not mix them, but you we are curious to what you think
UserSonos2MQTTSonos SpeakerPlay notification urlWhat is the current position?Here you goSave playback snapshotCurrent Track, Volume, Position, Mute & MetadataSet track uri, volume etc.Play notification trackWait for event or timeoutPlayback stopped (event)Play next notificationPlayback stopped (event)Restore full stateUserSonos2MQTTSonos Speaker
Text to speech
You can have your sonos speaker prononce some notification text, which is a pretty cool feature. But you’ll need some extra work. You’ll need a text-to-speech endpoint as described here. You have two options either host your own server or become a sponsor and get access to my personal hosted TTS server.
Either way you will have a TTS endpoint at hand. You can set it in the configuration or supply it with every request.
Option
Value
Environment variable
Config
Default language
en-US
SONOS_TTS_LANG
--ttslang
Default endpoint
http://some-server.domain.com/api/generate
SONOS_TTS_ENDPOINT
--ttsendpoint
Have a speaker speak by sending the following to sonos/uuid_of_speaker/control. Endpoint is optional (if set in environment), lang is options if set in config, gender, name, volume & onlyWhenPlaying are always optional.
{"command":"speak","input":{"text":"Someone at the front-door","endpoint":"https://your.tts.endpoint/api/generate","lang":"en-US","gender":"male","name":"Salli","volume":50,"onlyWhenPlaying":false,"delayMs":700}}
Experimental tts queue
There is a second implementation of the notification queue (used by TTS), just change speak to speaktwo in the above command. You should not mix them, but you we are curious to what you think
Text to speech on all speakers
Send this payload to sonos/cmd/speak to play it on all groups. Same parameters as above.
{"text":"Someone at the front-door","endpoint":"https://your.tts.endpoint/api/generate","lang":"en-US","gender":"male","name":"Salli","volume":50,"onlyWhenPlaying":false,"delayMs":700}
Text to speech explained
The text-to-speech method executes the following:
Ask the TTS endpoint what the url of the supplied text is.
If the server doesn’t have this file, it will generate the mp3 file on the fly.
The TTS endpoint returns the url of the mp3.
We call the .PlayNotification({}) command above, with the tts url.
UserSonos2MQTTText-to-speech serverRemote servicePlay text-to-speechHTTP post /api/generateHave mp3 for text?Generate mp3 for textHere you goSave file locallyUrl for mp3 filePlay notification url (see above)UserSonos2MQTTText-to-speech serverRemote service
This way you don’t have to worry about encoding the text so sonos understands it. Sonos will just get a regular url to the mp3 file with the spoken text.
The server I’ve build is based on Amazon Polly, but I invite eveybody to build their own if you want to support an other tts service. You can replace it with any other TTS service as long as it expects a post request with the data below and responds with a json message with either uri or cdnUri. The sonos speaker needs the .mp3 at the end to be able to play the file smoothly.
TTS API
Request POST to https://your-tts-api.com/api/generate
{"text":"Hello from polly","lang":"en-US","gender":"male"}