In my quest to continually improve my multi-room audio setup, one thing that has bothered me is getting Spotify to play in multiple rooms. My current solution has been to run a Windows VM with the Spotify client, capture the audio using TuneBlade, and then play it out to the various Raspberry Pi’s on the network that are running shairport-sync so they can receive AirPlay signals.
Works pretty well – but means I need to have that Windows VM working all the time. This isn’t a scalable solution to locations where the VM/Windows machine on-all-the-time isn’t an option.
So, I’m now trialling using Mopidy – an extensible music server written in Python. Mopidy will run on a Raspberry Pi, and has an extension that allows it to connect to Spotify…no Windows machine needed!
To get it up and running, I followed the installation instructions, with a few key call-outs as I was getting this running on a Raspberry Pi as the server as well:
- Install raspbian-lite (Jessie) on the Raspberry Pi of choice and get it all set up.
- Follow these instructions – specifically:
wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add - sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/jessie.list sudo apt-get update sudo apt-get install mopidy
/etc/mopidy/mopidy.conffile looks like:
[core] cache_dir = /var/cache/mopidy config_dir = /etc/mopidy data_dir = /var/lib/mopidy [logging] config_file = /etc/mopidy/logging.conf debug_file = /var/log/mopidy/mopidy-debug.log [local] enabled = false #Note: this is just because I wasn't setting up local music at this point media_dir = /var/lib/mopidy/media [m3u] playlists_dir = /var/lib/mopidy/playlists [mpd] enabled = true hostname = :: enabled = true username = **** #My Spotify username password = **** #My Spotify password [http] enabled = true hostname = :: port = 6680 static_dir = "" zeroconf = Mopidy HTTP server on $hostname [websettings] enabled = true musicbox = false config_file = /etc/mopidy/mopidy.conf #output = autoaudiosink output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo
- To get Mopidy working as a service, I used
sudo systemctl enable mopidybut you can use
sudo dpkg-reconfigure mopidyfor any Debian-based system.
- Then, I needed to install
pip– but, it needed to be the Python 2.7 version. To install that, I used
apt-get install python-pip2.
pip, I could now install the various add-ins for using and supporting Spotify, namely:
pip2 install Mopidy-Mopify pip2 install Mopidy-Moped pip2 install Mopidy-WebSettings pip2 install Mopidy-Iris
To pipe the audio across the network, I needed to install Snapcast server on the same Raspberry Pi, and then Snapclient on the various clients. So, that looks like:
- Get the latest compiled release for ARM (RPi) with
on the client and then on the server:
- Install, with dependencies:
dpkg -i snapserver_0.11.1_armhf.deb sudo apt-get -f install
on the server, and then on the client:
dpkg -i snapclient_0.11.1_armhf.deb sudo apt-get -f install
- The addition to the
mopidy.conffile of the
outputsection will pipe the audio from
mopidyto any Snapclient that is listening.
snapclient -lwill list the USB devices and other sound cards on the client, and then your
/etc/default/snapclientshould look something like
# defaults file for snapclient # start snapclient automatically? START_SNAPCLIENT=true # Allowed options: # --help produce help message # -v, --version show version number # -h, --host arg server hostname or ip address # -p, --port arg (=1704) server port # -l, --list list pcm devices # -s, --soundcard arg (=default) index or name of the soundcard # -d, --daemon [=arg(=-3)] daemonize, optional process priority [-20..19] # --user arg the user[:group] to run snapclient as when daemonized # --latency arg (=0) latency of the soundcard # -i, --instance arg (=1) instance id USER_OPTS="--user snapclient:audio" SNAPCLIENT_OPTS="-s 11"