Multi-room audio with Mopidy and Snapcast

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:

  1. Install raspbian-lite (Jessie) on the Raspberry Pi of choice and get it all set up.
  2. Follow these instructions – specifically:
    wget -q -O - | sudo apt-key add -
    sudo wget -q -O /etc/apt/sources.list.d/mopidy.list
    sudo apt-get update
    sudo apt-get install mopidy
  3. My /etc/mopidy/mopidy.conf file looks like:
    cache_dir = /var/cache/mopidy
    config_dir = /etc/mopidy
    data_dir = /var/lib/mopidy
    config_file = /etc/mopidy/logging.conf
    debug_file = /var/log/mopidy/mopidy-debug.log
    enabled = false #Note: this is just because I wasn't setting up local music at this point
    media_dir = /var/lib/mopidy/media
    playlists_dir = /var/lib/mopidy/playlists
    enabled = true
    hostname = ::
    enabled = true
    username = **** #My Spotify username
    password = **** #My Spotify password
    enabled = true
    hostname = ::
    port = 6680
    static_dir = ""
    zeroconf = Mopidy HTTP server on $hostname
    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
  4. To get Mopidy working as a service, I used sudo systemctl enable mopidy but you can use sudo dpkg-reconfigure mopidy for any Debian-based system.
  5. Then, I needed to install pipbut, it needed to be the Python 2.7 version. To install that, I used apt-get install python-pip2.
  6. Using 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:

  1. Get the latest compiled release for ARM (RPi) with

    on the client and then on the server:

  2. 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
  3. The addition to the mopidy.conf file of the output section will pipe the audio from mopidy to any Snapclient that is listening.
  4. snapclient -l will list the USB devices and other sound cards on the client, and then your /etc/default/snapclient should look something like
    # defaults file for snapclient
    # start snapclient automatically?
    # 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"