Update Required: New Sonos Integration

@CodeMunky @paul1964 not sure if you have a raspberry pi available to use but I just set one up to use jishi Sonos http api. It satisfied my need for tts. I changed my webcore pistons to make a get request to my raspberry pi which then makes it way to Sonos.
Works great so far. I also went a step further and setup Microsoft Cognitive services in azure to use their TTS APIs. Now I have different voice options and the speaking is more natural.

2 Likes

Hi, Thanks that looks interesting. I’ve started looking through the documentation.
Are there any beginners guides on how to install? Also could you share an example of calling from webcore? I’m struggling to get it to work. I’ve got it to control my sonos, but it crashes out when I try a TTS message. I installed as follows on the PI (I didn’t want to use the Pi image as I already use the PI for other taks)

Ensure Pi is up to date
sudo apt-get update sudo apt-get dist-upgrade

Download nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

Install nodejs
sudo apt-get install -y nodejs

Confirm version
node -v

Download from http://jishi.github.io/node-sonos-http-api/
into
mkdir /home/pi/Sonos/
cd /home/pi/Sonos/jishi-node-sonos-http-api-0d03be9

Install Dependancies
npm install --production

Create settings.json
{
“voicerss”: “Your api key for TTS with voicerss”
}

Start server

npm start

I’m testing TTS on the pi with the following
curl http://localhost:5005/lounge/say/hello

the server then fails with
/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/lib/helpers/is-radio-or-line-in.js:4
return uri.startsWith(‘x-sonosapi-stream:’) ||
^

TypeError: Cannot read property ‘startsWith’ of undefined
at isRadioOrLineIn (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/lib/helpers/is-radio-or-line-in.js:4:13)
at Object.say (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/lib/actions/say_v2.js:64:12)
at handleAction (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/lib/sonos-http-api.js:110:35)
at HttpAPI.requestHandler (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/lib/sonos-http-api.js:87:5)
at /home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/server.js:80:13
at Server.finish (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/node_modules/node-static/lib/node-static.js:111:13)
at finish (/home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/node_modules/node-static/lib/node-static.js:170:14)
at /home/pi/Sonos/jishi-node-sonos-http-api-0d03be9/node_modules/node-static/lib/node-static.js:144:17
at FSReqWrap.oncomplete (fs.js:123:15)

I think the download link I used was the problem. I used the link from github and its working. Instructions below for anyone else who needs to set it up on a raspberry Pi.
Ensure Pi is up to date
sudo apt-get update
sudo apt-get dist-upgrade

Download nodejs
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

Install nodejs
sudo apt-get install -y nodejs

Confirm version
node -v

Download from https://github.com/jishi/node-sonos-http-api
into
mkdir /home/pi/sonos/
cd /home/pi/sonos/node-sonos-http-api-master
Install Dependancies
npm install --production

Create a free account on www.voicerss.org and obtain your API key

Create settings.json
{
“voicerss”: “Your api key for TTS with voicerss”
}

Start server

npm start

test via browser or curl
http:localhost:5005/kitchen/say/test

To call from webcore
image

1 Like

Thanks for the advice @paul1964 and @koyfam!

I have been holding off using a Pi in my Smarthome setup as I’ve always been able to get around problems another way, but this may have tipped me over the edge.

Looks like I have some work to do!

Cool. Glad you got it working.

@hoyfam - Many Thanks for the suggestion, its a good solution.

@CodeMunky - I’d rather keep things simple and not use the Pi, however, this solution offers several benefits over the soon to be depreciated method.

  • After playing text,music correctly resumes
  • You can easily play a track from your music library
  • Clips can be stored locally and played e.g door_bell_sound.mp3

If you follow the steps I took, it should only take 30 mins to setup. I just need to get it to auto run now when the PI boots.

3 Likes

Those benefits sound very similar to the ones provided by the new websocket integration, except for the locally stored track. Although there are some canned sounds in the new app you can play.

There is another very significant benefit to using jishi’s Sonos http api, and that is group management. jishi’s code provides for multiple “preset” groups and makes it easy to create, join and leave groups. Combining this with webCoRE automation, I can easily join my upstairs speakers to my downstairs speaker group, or even move music from one group to the other.

1 Like

To get mine to run at startup I added these lines to rc.local file in /etc

You ca modify the path to match where your server.js script is located.

node /home/pi/node-sonos-http-api/server.js < /dev/null &
exit 0

For some reason I tried a custom automation in the new app but can’t seem to find a way to control the volume. The tts notifications are extremely loud even if my speaker volume is set very low. It seems hard coded.

The jishi api works great.

Appreciate if someone can guide me on what app can i now use to announce activities around the home on our Sonos speakers ?

BigTalker no longer works.

thanks

New app automation creator. @joshua_lyon can SharpTools rule creator do audio announcement with the new Sonos websocket DTH?

Yes, SharpTools can do audio announcements. TTS is a bit more tricky due to the changes made to the websocket DTH.

SharpTools has access to all of the methods that the new Sonos Websocket DTH exposes including playTrack() and related commands. The playText() method which performed text-to-speech with the previous Sonos DTH is no longer available in the Sonos Websocket DTH.

So there’s not a built-in TTS method directly on the driver anymore, but you can play any file that’s hosted on the web.

So one approach is to use a service like fromtexttospeech.com and then use the resulting file in the playTrack() method.

Create the TTS File

  1. Navigate to fromtexttospeech.com
  2. Enter in your desired phrase and tap Create Audio File
  3. (For testing purposes) Right-click the link of the resulting file and choose ‘Copy link address’

Note: I have no idea how long they keep the files hosted for you, so you’re probably better off downloading the file and storing it on Dropbox, Google Drive, etc. and then using a link directly to your stored copy of the file.

Create the Rule
(Assuming you already have your Sonos authorized in SharpTools)

  1. Open the SharpTools.io Rule Engine
  2. Tap Create Rule
  3. Under Flow, add a new ActionDevice
  4. Choose your Sonos device and select the playTrack() command
  5. Enter the URL to your TTS file in the first string argument
    Optionally: enter a target volume level for the number argument
    (or switch the ‘Advanced’ toggle on in the top-right corner and delete the number argument)

Note: In most cases, you’ll want to have some sort of Trigger defined in the rule otherwise the rule will never run.

4 Likes

ugh, what a pain.

Well, it’s past Oct 17th and my Sonos devices have not automatically been updated as ST said they would. Not that I’m complaining.

1 Like

thank God I was using 3rd party device handlers for Sonos speakers (media renderer) and my TTS automation did not break.
but this is really very bad planned update by Samsung.
anyway, is there any good in this update ? (I mean apart from local execution)

What is your 3rd party device handler? I am hosed, can’t use my Sonos with BigTalker since the update.

I am using media renderer.
check here:

they both say “cheap sonos alt.” but the device handler also work with Sonos.

Actually one of the minions has actively said it won’t be worked on my them. Although playing has started working so someone has done something but volume isn’t working yet.

anyone know why the volume is SO LOUD?