Raspberry Pi as an AirPlay and Spotify Connect Receiver

ยท

A Raspberry Pi makes a great multi-protocol audio receiver – pair it with a set of speakers and you can stream to it via AirPlay from any Apple device, or via Spotify Connect directly from the Spotify app. This guide covers setting up both shairport-sync for AirPlay and Raspotify for Spotify Connect on a headless Raspberry Pi.

What you’ll need

  • A Raspberry Pi (Pi 3, 4, or 5 recommended – Pi Zero 2 W works well for a compact build)
  • A micro SD card with Raspberry Pi OS Lite installed
  • Speakers connected via 3.5mm jack or a USB audio adapter
  • An active Spotify Premium account (required for Spotify Connect)
  • SSH access to your Pi

1. Flash and set up

Use Raspberry Pi Imager to flash Raspberry Pi OS Lite (64-bit). In the imager’s advanced settings, set your hostname, enable SSH, and configure your Wi-Fi before writing. This means you can boot headless and SSH straight in – no monitor needed.

ssh pi@raspberrypi.local
sudo apt update && sudo apt upgrade -y

2. Install shairport-sync for AirPlay

shairport-sync is the gold standard open source AirPlay receiver. It supports AirPlay 1 (all Apple devices) and AirPlay 2 in recent builds.

Install the dependencies:

sudo apt install -y build-essential git autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev libplist-dev libsodium-dev libavutil-dev libavcodec-dev libavformat-dev uuid-dev xxd libglib2.0-dev

Clone and build shairport-sync:

git clone https://github.com/mikebrady/shairport-sync.git
cd shairport-sync
autoreconf -fi
./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2
make
sudo make install

Enable and start the service:

sudo systemctl enable shairport-sync
sudo systemctl start shairport-sync

Your Pi will now appear as an AirPlay speaker in Control Centre on iPhone, iPad, and Mac. The default name is the Pi’s hostname – you can change it in /etc/shairport-sync.conf under the general section:

general = {
  name = "Living Room Pi";
};

3. Install Raspotify for Spotify Connect

Raspotify wraps librespot into a convenient Debian package. It makes the Pi appear as a Spotify Connect device, so you can cast to it from the Spotify app on any device on your network.

Install it with the official script:

curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

Configure it in /etc/raspotify/conf. The key options:

LIBRESPOT_NAME="Living Room Pi"
LIBRESPOT_BITRATE="320"
LIBRESPOT_DEVICE_TYPE="speaker"

Restart the service after any config changes:

sudo systemctl restart raspotify

Open Spotify on your phone or laptop, tap the speaker icon, and you should see your Pi listed as an available device.

4. Running both at once

shairport-sync and Raspotify can run simultaneously without conflict – they each grab the audio output independently, and only one will be active at a time. There’s no configuration needed to make them co-exist; just ensure both services are enabled and running:

sudo systemctl status shairport-sync
sudo systemctl status raspotify

Both should show active (running).

Troubleshooting

Pi not showing up as AirPlay device: Check Avahi is running with sudo systemctl status avahi-daemon. AirPlay discovery uses mDNS, so Avahi needs to be active for the Pi to advertise itself on the network.

No audio output: Run aplay -l to list audio devices and confirm your output is detected. If you’re using a USB audio adapter, it may not be set as the default ALSA device. Check /etc/asound.conf or set LIBRESPOT_DEVICE in the Raspotify config to target your USB adapter explicitly.

Audio quality is poor: The Pi’s built-in audio is adequate but not hifi. A HiFiBerry HAT or a decent USB DAC like the AudioQuest DragonFly makes a significant difference, especially for AirPlay which can stream lossless audio from Apple Music.

Spotify Connect not appearing: Raspotify requires a Spotify Premium account. Free accounts don’t support Connect. Also ensure your phone and Pi are on the same network – Connect doesn’t work across VLANs without mDNS forwarding.

Going further

With AirPlay and Spotify Connect both running, you’ve got a capable wireless audio receiver that works natively with Apple devices and Spotify without any special apps on the sending device. A few things worth adding:

  • Add Bluetooth A2DP support alongside AirPlay and Spotify Connect – see our Raspberry Pi Bluetooth A2DP guide
  • Use a Pi Zero 2 W for a tiny, low-power build that runs all three protocols
  • Put the Pi in a project enclosure with a small amplifier board for a fully self-contained wireless speaker

Jonathan Mitchell, CTO | CITP | MSc


Leave a Reply