Skip to content

Instantly share code, notes, and snippets.

@AlexJHayward
Created January 17, 2021 18:34
Show Gist options
  • Save AlexJHayward/a6e9fa8a18247e9c25071d01ff2387f1 to your computer and use it in GitHub Desktop.
Save AlexJHayward/a6e9fa8a18247e9c25071d01ff2387f1 to your computer and use it in GitHub Desktop.
Setting up a RaspberryPi as an Audio Server for Spotify and Airplay.

Setting Up a Raspberry Pi as an Audio Server

0. Setup

This is optional, but I like to setup from fresh when the pi is just being used for one purpose:

  1. Install the Raspberyy Pi Images: https://www.raspberrypi.org/software/
  2. Install a fresh copy of Raspberry Pi OS Lite on to an SD card
  3. Configure WiFi to run the pi headless (pay attention to the capitalisation of the network name, one wrong character had me scratching my head for a while):
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<ISO alpha-2 country code>

network={
 ssid="NETWORK_NAME"
 psk="NETWORK_PASSWORD"
}
  1. Save that with LF line endings as wpa_supplicant.conf in the root boot directory on your SD card.
  2. Enable SSH on the pi by doing touch ssh inside boot.
  3. Safely eject your SD card and put it in the Pi.
  4. Plug the Pi in to power and audio through the audio jack.
  5. Wait a few minutes for it to join the network. You can run nmap -sn 192.168.1.0/24 to see everything on the network or just ping raspberrypi.local until it appears.

1. Airplay

This is Liz Miller's brilliant guide found here. No credit taken, I just wanted to put all these instructions in one place for when my Pi inevitably shits the bed and I have to set it all up again.

  1. ssh pi@raspberrypi.local
  2. sudo apt-get update && sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman
  3. git clone https://github.com/mikebrady/shairport-sync.git
  4. cd shairport-sync
  5. autoreconf -i -f
  6. ./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata
  7. make
  8. sudo make install
  9. Liz says here to run sudo raspi-config and then go Advanced Options > Audio > Force 3.5mm (‘headphone’) jack. I didn't have to do this, the Audio section wasn't showing up in advanced options, maybe it's because my Pi is old 🤷🏻‍♂️.
  10. amixer sset PCM,0 100% from the guide didn't work for me, but you can adjust the volume of the Pi by running alsamixer and just configuring it through there.
  11. sudo systemctl enable shairport-sync so that it launches on pi boot.

And done! It should show up as a new airplay speaker called Raspberrypi.

2. Spotify

Although I've gone full Apple plenty of people use spotify, so it's pretty trivial to get a spotify connect server up and running using raspotify. This again is from another great guide written by Emmet here.

  1. sudo apt update && sudo apt upgrade
  2. sudo apt install -y apt-transport-https curl
  3. curl -sSL https://dtcooper.github.io/raspotify/key.asc | sudo apt-key add -v -
  4. echo 'deb https://dtcooper.github.io/raspotify raspotify main' | sudo tee /etc/apt/sources.list.d/raspotify.list
  5. sudo apt update
  6. sudo apt install raspotify

and that's it, it's running. If you want to make changes to the configuration (name, icon in spotify, bitrate etc) then run sudo nano /etc/default/raspotify, change the appropriate values, save + quit, then run sudo systemctl restart raspotify to restart it.

@looolz
Copy link

looolz commented Apr 3, 2024

Last Spotify step: sudo nano /etc/default/raspotify is now replaced by sudo nano /etc/raspotify/conf

Thanks so much for this guide!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment