How to build an AirPlay receiver using a Raspberry Pi

VAIBHAV HARIRAMANI
6 min readAug 24, 2024

--

Building a Raspberry-Pi based AirPlay server can be a solution, adding music-streaming functionality to your old receivers or amplifiers, classic speakers or older TVs. Unfortunately, you won’t be able to stream video to your Raspberry-Pi — but with minimal power usage, HDMI support, easy setup, and integration with your AirPlay-enabled devices, it’s a great way to level up your audio game at home without splashing the cash on new devices.

What you’ll need

  • A Raspberry
  • Wi-Fi connection

Working

We’ll be using an open-source project called Shairport-Sync, a Linux and FreeBSD audio player which originally started supporting AirPlay 1 and now supports AirPlay 2. We’re using a full-sized Raspberry Pi 3b here, but it should run well even on an older Raspberry Pi 2 or a Raspberry Pi Zero 2 W with a suitable USB or I2S card. We’ll be using HDMI to connect to a TV, but if you’re planning on connecting to a speaker or receiver without HDMI then you might want to consider an external DAC, as the inbuilt audio on the Pi isn’t particularly good. Network performance for AirPlay isn’t particularly important, so we’re connecting to our Pi 3 using the inbuilt
Wi-Fi.

Shairport-sync has some more complex requirements, requiring that ports 319 and 320 are available to use. This can cause problems if you’re turning an old Mac into a shairport-sync server, as these ports are already used by macOS. You also cannot host multiple shairport-sync servers on the same IP address, as this causes problems for AirPlay.

Here’s how I have done

Go to this link here to set up your raspberry pi. Once setup is done let’s begin creating AirPlay receiver using a Raspberry Pi

In the commands below, note the convention that a # prompt means you are in superuser mode and a $ prompt means you are in a regular unprivileged user mode.

You can use sudo ("SUperuser DO") to temporarily promote yourself from user to superuser, if permitted. For example, if you want to execute apt-get update in superuser mode and you are in user mode, enter sudo apt-get update.

Get Tools and Libraries

# apt update
# apt upgrade # this is optional but recommended
# apt install --no-install-recommends build-essential git autoconf automake libtool \
libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev \
libplist-dev libsodium-dev libavutil-dev libavcodec-dev libavformat-dev uuid-dev libgcrypt-dev xxd

Download and enable NQPTP

nqptp is a daemon that monitors timing data from PTP clocks it sees on ports 319 and 320. It maintains records for one clock, identified by its Clock ID.

It is a companion application to Shairport Sync and provides timing information for AirPlay 2 operation.

Installation

$ git clone https://github.com/mikebrady/nqptp.git
$ cd nqptp
$ autoreconf -fi
$ ./configure --with-systemd-startup
$ make
# make install

If you are installing nqptp for the first time, enable it and start it:

# systemctl enable nqptp
# systemctl start nqptp

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
# make install

Test

At this point, Shairport Sync should be built and installed but not running. If the user you are logged in as is a member of the unix audio group, Shairport Sync should run from the command line:

$ shairport-sync

Enable in background

Once installed, start shairport-sync with the following:

sudo systemctl start shairport-sync

Check the status of the shairport-sync process with

sudo systemctl status shairport-sync

While we’re here, we’ll also enable the service, so it automatically restarts when the Pi is switched on or off. Do this with the following:

sudo systemctl enable shairport-sync

Once the service is up and running, we’ll need to change some default config values. This is where things get more complex. Start by listing out your available audio devices using:

aplay -l

Aplay is a command line sound recorder and player designed for ALSA, a part of the Linux Kernel designed to facilitate interfacing with sound cards. The -l flag prints out available devices. The output you see will depend on your Pi, and what audio devices are connected. For our Raspberry Pi 3b, we have two devices: the internal audio headphones and our HDMI output vc4-hdmi. Make a note of the name of the audio device you’ll be using — you’ll need it in the next step. We’d recommend you use the Pi’s HDMI jack (at least to start with.) The Pi’s default DAC isn’t particularly good, and getting external USB DAC’s running can be a pain.

We’ll be using the vchdmi output to play audio. To do this, open /etc/shairport-sync.conf using a text editor you’re comfortable with. We’re using Vi. Remember to open the file as root.

sudo vi /etc/shairport-sync.conf

Once opened, scroll down in shairport-sync.conf file to the section labeled alsa. There you’ll find an option labeled output device. Remove the two comments from the start of the line (//) and replace the value default with hw:<your audio device name>. You can drop any hyphens in the name, i.e.

output_device = "hw:vc4hdmi"

And then save and exit the file.

Limitations of Shairport-Sync

Not everything is implemented

Shairport-sync is an incomplete version of AirPlay-2 and has some limitations. Chiefly — you won’t be able to stream video to your Pi, nor share photos. Shairport-sync operates as an audio-only AirPlay server, making it ideal for upgrading speakers or smart TVs to stream audio into your living room, but no video. In my testing, I was able to stream audio from a video, i.e. watching a video on another device and playing audio through my Pi, which is a nice trick — but no actual video will appear on the TV. There are some other limitations, as documented on the projects ‘What works’ page:

Source: Github/Shairport-Sync

Shairport-Sync is great for old receivers, speakers or TVs

Shairport-sync isn’t perfect — ideally, we’d be able to stream video as well — but it is very easy to run (so it could run alongside other software on a newer Pi), reliable once configured and quick to set up. When connected to a TV, it also has the benefit of being a background service that doesn’t prevent you from using your Pi normally — so you could use the same Pi

Made with ❤️by Vaibhav Hariramani

Don’t forget to tag us

if you find this blog beneficial for you don’t forget to share it with your friends and mention us as well. And Don’t forget to share us on Linkedin, instagram, facebook , twitter, Github

More Resources

To learn more about these Resources you can Refer to some of these articles written by Me:-

Download THE VAIBHAV HARIRAMANI APP

The Vaibhav Hariramani App (Latest Version)

Download THE VAIBHAV HARIRAMANI APP consist of Tutorials,Projects,Blogs and Vlogs of our Site developed Using Android Studio with Web View try installing it in your android device.

Follow me

on Linkedin, instagram, facebook , twitter, Github

Happy coding ❤️ .

--

--

VAIBHAV HARIRAMANI

Hi there! I am Vaibhav Hariramani a Travel & Tech blogger who love to seek out new technologies and experience cool stuff.