My ultimate guide to the Raspberry pi audio server I wanted — Apple AirPlay

Mathieu Réquillart
3 min readApr 30, 2022

Part 8 — AirPlay

I also wanted to add AirPlay support to the Raspberry for my friends with Apple devices. It’s also a common service on most open source and commercial audio servers. The way to go is to install Shairport-sync. Installation is pretty easy, but configuration with PulseAudio is a bit tricky.
We’ll want to run Shairport-sync as a user systemd unit with our pi user and configure it to use our PulseAudio server as audio backend to bypass the limitations announced in the documentation.

$ sudo apt install shairport-sync
$ systemctl --user enable shairport-sync

This will copy default systemd unit in ~/.config/systemd/user/shairport-sync.service (if not you’ll have to create it), but we need to make some adjustments to make it work properly:
- Remove the Avahi mentions and User and Group directive which can’t be used within a user sytemd unit.
- Change the install method to default.target instead of multi-user to boot properly with user systemd
-
Change restart policy, for some reason Shairport-sync seems to start quicker than PulseAudio and fail to connect to it and start properly at boot.

~/.config/systemd/user/shairport-sync.service

[Unit]
Description=Shairport Sync — AirPlay Audio Receiver
Wants=sound.target
After=sound.target
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=simple
EnvironmentFile=-/etc/default/shairport-sync
ExecStart=/usr/bin/shairport-sync $DAEMON_ARGS

Restart=always
RestartSec=5

[Install]
WantedBy=default.target

Since we use our user pi instead of default shairport-sync user, we also need to edit a few dbus policies and to add our pi user in the owners of shairport dbus services. Place the following directives in the <busconfig> section

/etc/dbus-1/system.d/shairport-sync-dbus-policy.conf

<policy user=”pi”>
<allow own=”org.gnome.ShairportSync”/>
</policy>

/etc/dbus-1/system.d/shairport-sync-mpris-policy.conf

<policy user=”pi”>
<allow own=”org.mpris.MediaPlayer2.ShairportSync”/>
</policy>

$ sudo systemctl restart dbus

Finally, as we’re used in this seup, we configure shairport-sync to use PulseAudio backend instead of Alsa

general = {
name = “%H”;
// This means “Hostname” — see below. This is the name the service will advertise to iTunes.
output_backend = “pa”;
// Run “shairport-sync -h” to get a list of all output_backends, e.g. “alsa”, “pipe”, “stdout”. The default is the first one.
mdns_backend = “avahi”; // Run “shairport-sync -h” to get a list of all mdns_backends. The default is the first one.
};
pa = {
server = “127.0.0.1”;
// Set this to override the default pulseaudio server that should be used.
application_name = “Shairport Sync”;
//Set this to the name that should appear in the Sounds “Applications” tab when Shairport Sync is active.
};

We can finally start shairport-sync

$ systemctl --user start shairport-sync.service

And see it running and connected to PulseAudio

$ journalctl --user -u shairport-sync.service
Apr 18 01:05:53 rasponkyo systemd[688]: shairport-sync.service: Consumed 1.607s CPU time.
Apr 18 01:05:53 rasponkyo systemd[688]: Started Shairport Sync — AirPlay Audio Receiver.
$ pactl list clients
Client #20
Driver: protocol-native.c
Owner Module: 11
Properties:
application.name = “Shairport Sync”
native-protocol.peer = “TCP/IP client from 127.0.0.1:50616”
native-protocol.version = “34”
application.process.id = “2376”
application.process.user = “pi”
application.process.host = “rasponkyo”
application.process.binary = “shairport-sync”
application.language = “C”
application.process.machine_id = “94407542ae804e6f9e791df75037e3d2”

Using our new AirPlay server as a PulseAudio sink

Since version 11 PulseAudio natively supports AirPlay servers as sink, so we can use it as a remote sink as we did with PulseAudio TCP.

Then you can go in your sound settings and set the output to your new AirPlay server, running on port 5000.

--

--