Setup
Since one of my goals was to also stream from an analog input, it creates an extra layer of complication. My first iteration was simply multi-room Spotify streaming in anticipation of the upcoming Spotify HiFi service but every tutorial I found seemed unnecessarily complicated and seemed to unnecessarily use extra components like mopidy (this still be added as a source later on if needed). I ended up using Snapcast to setup the multi room aspect since it easily allows any kind of source as an input and has a web control interface/API built in. The first set of instructions is just for digital only streaming over WiFi such as Airplay or Spotify Connect.
Hardware
The Pi Zero does not have an analog audio output, therefore I'm using the Pirate Radio line out hat for the Raspberry Pi from Adafruit. I got this one specifically since it has a screen that I can eventually use to add album art and/or EQ visualization. The added benefit to using this kind of hat is that it has a high quality 24-bit 192Khz digital analog converter (DAC) which allows for extremely high fidelity playback. The super HiFi probably doesn't matter as much to most people and could easily just use a normal sized Raspberry Pi 1/2/3/4 with the built in line-out however I personally still prefer the Pi Zero due to size.
Line-out options for the Pi that I tested:
- DAC shim from Pimoroni
- Least expensive yet still offer the hifi DAC hardware
- Pirate Radio DAC w/ LED Screen
- Has built in LCD screen and buttons for album art additions and playback control
- Pi Zero iPod 30-Pin Adapter
- A bit pricy but powers the Pi Zero, has built in hifi DAC, and handles audio all via the old 30 pin iPod connector. Amazing drop in solution for any iPod dock
Spotify/Airplay
This setup is the most simple. I was even able to run both the snapserver and the snapclient from a Pi Zero W however I wouldn't recommend this if you plan on having more than a couple clients. Having a dedicated Pi 3 or Pi 4 connected to ethernet is the ideal scenario for the server but not critical if you have good WiFi speed and coverage.
- Snapcast Server
- Burn Raspberry Pi OS image to the SD card
- If using a DAC edit the config.txt with the configuration to enable it. For hifiberry compatibile devices, find the line with "dtparam=audio=on" and replace it with with the below
dtparam=audio=off dtoverlay=hifiberry-dac gpio=25=op,dh dtparam=spi=on
- Configure WiFi (Optional, if not using ethernet)
- Take note of the IP address
- Optionally update the file /etc/hostname with a friendly name to easily reference in your network such as "snapserver"
- Reboot
- Download and install snapserver and optionally raspotify if your server is also hooked up to a speaker. These commands can be copy and pasted into the terminal or remotely via SSH. Installing raspotify will also allow the speaker to picked individually from Spotify.
# v0.25.0 is the latest as of this post # Recommended to install the latest release specific to the OS being used # This is specific to the 32bit Raspberry Pi OS wget https://github.com/badaix/snapcast/releases/download/v0.25.0/snapserver_0.25.0-1_armhf.deb # Install snapserver packages sudo apt install -y ./snapserver_0.25.0-1_armhf.deb # Install Raspotify curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
# Edit the /etc/snapserver.conf file # Replace "source = pipe:///tmp/snapfifo?name=default" with the below line # devicename and default volume can be modified source = spotify:///librespot?name=Spotify&devicename=AllSpeakers&volume=35
Edit /etc/default/raspotify and update the following values. For most raspberry Pis using a DAC and built in audio turned off the device should be "hw:0,0" however USB or other external sounds cards may be registered as different devices. Use the command "aplay -l" to verify.
# Set whatever you want your device to be names DEVICE_NAME="kicker" # Verify this is the correct device using command "aplay -l" OPTIONS="--device hw:0,0" # Currently 320 is the highest quality supported by Spotify but should change soon with the release of their HiFi service BITRATE="320" # Quality of life options including the default volume level to start at VOLUME_ARGS="--enable-volume-normalisation --volume-ctrl linear --initial-volume=50"
Airport support can be added by installing shairport-sync but not required for Spotify streaming. Add airplay as an additional source in the /etc/snapserver.conf file
# To add password append "&password=<my-password>" to the bellow source = airplay:///<path/to/shairport-sync>?name=Airplay&devicename=AirportAllSpeakers
- Reboot the Pi and plug it into the aux input on the speaker. Both the snapcast server that I named "AllSpeakers" and the individual speaker show up as a source in the Spotify Connect menu. Since no clients have been setup to connect to the snapcast server, selecting only the individual Raspotify device will work so far.
- Snap Clients - Connecting to the server
Repeat these steps for any new speaker/client you want to add to the system. Optionally install Raspotify/Airplay just like the above steps to play to individual speakers.- Download and install the snapclient specific to your OS
# Download snapclient package for 32bit Raspberry Pi OS wget https://github.com/badaix/snapcast/releases/download/v0.25.0/snapclient_0.25.0-1_armhf.deb # Install pacakge sudo apt install -y ./snapclient_0.25.0-1_armhf.deb
Edit client config at /etc/default/snapclient to connect to your server
SNAPCLIENT_OPTS="-h <ip-address-of-server>"
Restart the snapclient service
sudo systemctl restart snapclient
Now anything being played through the SnapServer will automatically start playing on any client speaker
- Download and install the snapclient specific to your OS
Adding Analog Input
todo