SONOS, 'say' what?

Is there any chance to install the server on a Windows 10 based openHAB server system instead of a RasPI? Any instructions on that?

It should be possible to install node js on a Windows system: Node.js ā€” Download Node.jsĀ®

So today, tried this, but failed. Basically, thereā€™s no sound from my sonos players. The only thing that I can see happens, is that the player are ungrouped, but then nothing.

If I try to play a playlist, I get ā€œExpected statusCode 200, but got 500ā€ on the RPI.
If I try the say command, I get;

Using cached tts message file: 777a8ad4f7e604eaa2280c2fd4e9264eddd53c1e-en-gb.mp3
info: applying preset players=[roomName=Bibliotek, volume=40], state=playing, playMode=NORMAL, uri=http://10.1.200.109:5005/tts/777a8ad4f7e604eaa2280c2fd4e9264eddd53c1e-en-gb.mp3
debug: ungrouping Bibliotek to prepare for grouping
STOPPED 
debug: emitting group-volume
STOPPED 

No sure what could be wrong - does this output look normal to you guys?
I am running this on a RPI3, node.js 6.3.1 raspian jessie lite, 2016-05-27

Full session;

> sonos-http-api@0.19.0 start /home/pi/sonos
> node server.js

info: binding SSDP to port 1905
info: discovering all IPs from lo
info: discovering all IPs from eth0
info: relevant IPs 10.1.200.109=null
info: notification server listening on port 3500
http server listening on port 5005
no preset file, ignoring...
info: scanning for players in ip 10.1.200.109
info: subscribing to topology 10.1.200.178
info: using local endpoint 10.1.200.109
Initializing player Garage
Initializing player Sovrum
Initializing player Badrum
Initializing player Bibliotek
Initializing player Vardagsrum
debug: emitting group-volume
Expected statusCode 200, but got 500
Expected statusCode 200, but got 500
Expected statusCode 200, but got 500
Expected statusCode 200, but got 500
Expected statusCode 200, but got 500
Using cached tts message file: 777a8ad4f7e604eaa2280c2fd4e9264eddd53c1e-en-gb.mp3
info: applying preset players=[roomName=Bibliotek, volume=40], state=playing, playMode=NORMAL, uri=http://10.1.200.109:5005/tts/777a8ad4f7e604eaa2280c2fd4e9264eddd53c1e-en-gb.mp3
debug: ungrouping Bibliotek to prepare for grouping
STOPPED 
debug: emitting group-volume
STOPPED 

Any hints welcome!

@James_Bruce - Iā€™m attempting to follow your setup tutorial on Windowsā€¦but am running into the following error when trying to download the the package from GitHub.

Any thoughtsā€¦

It looks like youā€™re trying to use Git from within Node. The Git command is for the Linux command line - Iā€™m not sure how youā€™d use it on Windows, but you can just go to that URL and download the Sonos package instead, then jump back into Node environment to run it.

Thanks for thatā€¦is there a special place I should put it so NODE knows where to pull from?

What command would I use to install, the next in your list on the instructions?

npm install production

Thanks,

Squid

@James_Bruce : Do you perhaps have any suggestion regarding my problem?
Is the STOPPED to be expected etc?
(your guide was excellent!)

Itā€™s possible a software update broke things - check the github for Sonos project to see if anyone else is having the same problem. 500 and 200 are http status codes, so itā€™s saying the Sonos devices are responding with a generic 500 server error, while the node app expects 200 ā€œokā€. My best guess is that Sonos changed something and the bridge will need to be patched.

@vespaman @James_Bruce

I was able to get the package installed on my windows machine, but am running into the same error as Vespamanā€¦

The server processes the command, stops the music that is playing and says nothing.

info: applying preset players=[roomName=Foyer, volume=40], state=playing, playMode=NORMAL, uri=http://10.5.1.25:5005/tts/f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0-en-gb.mp3
debug: ungrouping Foyer to prepare for grouping
STOPPED
STOPPED
debug: emitting group-volume
STOPPED
STOPPED

Well, Iā€™ve just checked my own install, but on restarting, Node disappeared. :frowning: I suggest asking this on the Sonos http project Github page, as itā€™s a bit beyond me and the developer will know more. Sorry!

Turns out that node 5 or 4 is needed, node 6 is not supported right now. Iā€™ll start from scratch with my PI.
Edit: got it to work with 5.5.0. :slight_smile:

Thanks for the info, Iā€™ll update the article to reflect that Node 6 is not supported.

I can confirm as well, I reverted to 4.4.7 and everything plays as intended!

Thanks so much for the assistance.

It might be useful for some to know that the beta branch allows volume on say/sayall. I found the fixed volume too low for my setup.

@James_Bruce,

many thanks for the great tutorial!
Iā€™ve tried everything you suggested on a ubuntu server machine, but starting the api fails with the following output:

phate@prometheus:~/sonos$ sudo npm start

> sonos-http-api@1.0.0-beta.22 start /home/phate/sonos
> node server.js

no settings file found, will only use default settings
module.js:341
    throw err;
    ^

Error: Cannot find module 'fuse.js'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/phate/sonos/lib/music_services/libraryDef.js:2:14)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/phate/sonos/lib/actions/musicSearch.js:9:20)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)

npm ERR! Linux 4.4.0-36-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v5.12.0
npm ERR! npm  v3.10.7
npm ERR! code ELIFECYCLE
npm ERR! sonos-http-api@1.0.0-beta.22 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sonos-http-api@1.0.0-beta.22 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sonos-http-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sonos-http-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sonos-http-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/phate/sonos/npm-debug.log

When checking, the js is actually there:

phate@prometheus:~/sonos$ cd node_modules/fuse/bin/
phate@prometheus:~/sonos/node_modules/fuse/bin$ ls -al
insgesamt 20
drwxrwxr-x 2 phate phate 4096 Dez 10  2013 .
drwxrwxr-x 6 phate phate 4096 Sep 12 17:27 ..
-rwxrwxrwx 1 phate phate 2467 Dez 10  2013 fuse.js

I tried around a lot, including (re-)installing fuse again via npm install -g fuse and this only brings up some warning about minimatch - no error or anything.

phate@prometheus:~/sonos$ sudo npm install -g fuse
npm WARN deprecated minimatch@0.0.5: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/usr/bin/fuse -> /usr/lib/node_modules/fuse/bin/fuse.js
/usr/lib
ā””ā”€ā”€ fuse@0.4.0 

Do you happen to have an idea what might be the root of all evil?
npm is version 3.10.7 and node-v reveals v5.12.0 (just as in your tutorial).

I tried a lot in order to solve this problem, but did not yet have any success. It would be really great if someone had an idea. Many thanks in advance!

Hi David. Thatā€™s beyond me Iā€™m afraid - probably best to ask the creator on their Github issues page: https://github.com/jishi/node-sonos-http-api/issues

I havenā€™t come to the part which involves setting up Sonos and playing custom voice messages yet (But I plan on getting there eventually).

Why not creating a wav or mp3 file on the fly in linux?
You could then play it with the x-rincon-mp3radio:// that Kai suggested.

Iā€™m thinking in terms of a bash script:

echo "This is a wave file i just created" > text.msg
espeak --stdout -f text.msg | tee -a wavefile.wav
cp wavefile.wav /some/place/where/i/canaccess/it/viauri

Seems like the wave file will be generated quickly enough.

Guess this could be combined with MQTT where mqttwarn could trigger the bash-script if the content should be dynamic.

I had a similar issue, and after hunting around for much longer than needed, I had to remove the node modules folder and reinstall npm.

I did many sudo npm install -g <package> though as the install threw more than a few warnings.

cd sonos    
rm -rf node_modules
npm install

Was what fixed it for me.

Many thanks for your input, guys!
Actually, the suggestion brought up by pahansen solved it for me :).
@Seaside: Nice idea also! Iā€™ve not had this possibility in mind. Iā€™d need to figure out how to execute these commands from within a rule though and ensure that playback is performed only when the .wave file is ready, but not before. As Iā€™d like to have the system ā€œtalkingā€ in German though, Iā€™m currently trying to get the solution via voiceRSS running instead.

Iā€™m now struggeling with 2 problems still:

  1. Iā€™m trying to have the API starting up automatically during the boot process using rc.local:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/bin/node /home/phate/sonos/server.js
exit 0

Unfortunately, this does not work out during system startup and when checking rc.localā€™s status, Iā€™m getting confronted with the following:

rphate@prometheus:~$  systemctl status rc-local.service
ā— rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           ā””ā”€debian.conf
   Active: failed (Result: exit-code) since Fr 2016-09-16 19:09:33 CEST; 3min 11s ago
  Process: 1332 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)

Sep 16 19:09:33 prometheus rc.local[1332]: Error: Cannot find module '/home/phate/sonos/server.js'
Sep 16 19:09:33 prometheus rc.local[1332]:     at Function.Module._resolveFilename (module.js:339:15)
Sep 16 19:09:33 prometheus rc.local[1332]:     at Function.Module._load (module.js:290:25)
Sep 16 19:09:33 prometheus rc.local[1332]:     at Function.Module.runMain (module.js:447:10)
Sep 16 19:09:33 prometheus rc.local[1332]:     at startup (node.js:148:18)
Sep 16 19:09:33 prometheus rc.local[1332]:     at node.js:405:3
Sep 16 19:09:33 prometheus systemd[1]: rc-local.service: Control process exited, code=exited status=1
Sep 16 19:09:33 prometheus systemd[1]: Failed to start /etc/rc.local Compatibility.
Sep 16 19:09:33 prometheus systemd[1]: rc-local.service: Unit entered failed state.
Sep 16 19:09:33 prometheus systemd[1]: rc-local.service: Failed with result 'exit-code'.
phate@prometheus:~$ 

It works out when manually triggered after bootup from within a terminal session though:

phate@prometheus:~$ /etc/rc.local
http server listening on port 5005
no preset file, ignoring...

Iā€™m now wondering what might be the reason for this behavior. As rc.localā€™s commands are executed using root privileges, I donā€™t expect a permission issue being the problem here.
Does anybody happen to have an idea?

  1. The length of the message possible is apperently rather limited. Thinking about e.g. reading out new emails or giving a bunch of status information upon presence detection, this limitation may become a problem. Did anybody experience something similar and found a solution?

Thanks a lot once again for your great support!

I did not test this myself, but do you want it to run as root?
You could try to use sudo. Put this in rc.local:

sudo -i -u phate /path/to/node /path/to/server.js &

That should work, since you can execute it logged in as user phate.