Raspberry Pi AirPlay Receiver
In this tutorial, we will be exploring how to setup a Raspberry Pi AirPlay Receiver. This tutorial basically involves you connecting your Raspberry Pi to your speakers then installing software so that it becomes recognised as an AirPlay receiver on your internet network. To setup your AirPlay Receiver we will be making use of the open source software called Shairport Sync.


This software allows the Raspberry Pi to act as an AirPlay receiver by implementing Apples proprietary protocols so that it can receive music from those devices.

This will allow you to play music from any AirPlay enabled device to your Raspberry Pi meaning you can use almost any iPhone product and even some Android products with a compatible app installed. A Raspberry Pi AirPlay Receiver is very simple and cost-efficient way to setup wireless speakers without the huge cost of buying a set of wireless speakers. It can easily help you modernise your speakers and help cut the cord.

As an added bonus, this tutorial works perfectly alongside our Raspberry Pi Alexa tutorial, and is great for bringing in music support to the tutorial.

Equipment List

Below are all the bits and pieces that I used for this Raspberry Pi AirPlay Receiver tutorial, you will need an internet connection to be able to complete this tutorial.

Recommended:

Raspberry Pi 2 or 3

Micro SD Card

Network Connection

Speakers

AirPlay enabled device

Optional:

Raspberry Pi Case

Setting up an Apple AirPlay Receiver

Setting up your Raspberry Pi AirPlay receiver is an incredibly simple task, as long as you have a good internet connection and a set of speakers to connect your Raspberry Pi to it is a fairly straight forward process.

1. Before we get started lets first run an update and upgrade on our Raspberry Pi to ensure we are running the latest software.

sudo apt-get update
sudo apt-get upgrade

2. Once that has completed we need to install several different packages, run the following commands on your Raspberry Pi to install all of the packages that we need.

sudo apt-get install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev
sudo apt-get install avahi-daemon libavahi-client-dev
sudo apt-get install libssl-dev

3. We will now clone the shairport-sync source to our Raspberry Pi. Shairport-Sync is the best fork of the original Shairport code and allows synching across multiple rooms.

Run the following commands on your Raspberry Pi to download the source code to your Raspberry Pi.

cd ~
git clone https://github.com/mikebrady/shairport-sync.git

4. Now that we have cloned the Shairport-Sync repository to our Raspberry Pi we can now build and install the Shairport software.

Before we get started though we must first move into the shairport-sync folder and configure the system. To do this we must run a few commands on our Raspberry Pi.

cd shairport-sync
autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

The autoreconf command setups the basic config file. The configure command further sets up the build system, telling it to utilize the ALSA audio backend, the Avahi network and set it to use OpenSSL for encryption.

5. With the configuration process now completed we can finally compile Shairport-sync and install it. We can run the two make commands below on our Raspberry Pi to compile and install Shairport-Sync to the device. This will setup numerous things including the auto start script.

make
sudo make install

6. Now that we have built and installed all the software we need to setup our Raspberry Pi AirPlay receiver we can get on with setting it up. We need to first create a user and a group that has access to the audio hardware. We can do this by running the following commands on your Raspberry Pi:

sudo groupadd -r shairport-sync >/dev/null
sudo useradd -r -M -g shairport-sync -s /usr/bin/nologin -G audio shairport-sync >/dev/null

7. To enable the Shairport Sync software to start automatically at system startup you need to enter the following command into terminal on the Raspberry Pi:

sudo systemctl enable shairport-sync

8. Finally we can startup the Shairport software immediately by running the command below on our Raspberry Pi:

sudo service shairport-sync start

You should now be able to play audio files through your Raspberry Pi AirPlay Receiver using any AirPlay capable device. If you are using a non-apple device such as an Android device there are few apps that allow you to still utilize Airplay.

On your AirPlay enabled device your Raspberry Pi AirPlay receiver should appear as “RaspberryPi” in the devices list, please note that this name will be the same as your devices host name. If you would like to know how to change your Raspberry Pi’s hostname, you can check out our raspi-config guide.

Improving the Analogue Audio output

With our Raspberry Pi AirPlay receiver now setup. There are several different things we can do to improve it. The first of these is to change the Raspberry Pi so it will utilize a newer version of the audio driver.

To run this improved audio driver and get the benefits of it fully there is a few changes we will have to make. If you would like to read about the audio driver you check out this topic on it on the Raspberry Pi forums.

1. Firstly we need to update the Raspberry Pi’s firmware, we can do this by running the following command, it can take some time. Make sure your Raspberry Pi doesn’t lose power during this.

sudo rpi-update

2. Once the firmware update has completed turn off your Raspberry Pi and take out your SD Card. Once you have taken out your SD Card insert the SD Card into a reader connected to a computer. The reason for this is that we need to modify the Raspberry Pi’s boot config file

The file we are after is located at /boot/config.txt on the SD Card, open it up with your favourite text editor. Add the following new line to this file:

audio_pwm_mode=2

Once you have edited this file, you can save it and place the SD Card back into your Raspberry Pi and power it back on.

3. With your Raspberry Pi powered back on, there is two more things we need to do before the improved analogue audio driver will work well with Shairport. The next step is to set it so the analogue jack is the main audio out and not the HDMI output.

We can utilize the following command in the Raspberry Pi’s terminal to do this:

amixer cset numid=3 1

4. Now there is one final thing we must do to finish improving our Raspberry Pi AirPlay device and that is to modify the volume db Range that Shairport uses. We can modify the range by changing it in the configuration file.

Run the following command to begin editing the configuration file.

sudo nano /usr/local/etc/shairport-sync.conf

5. Within this file make the following changes:
Find

//      volume_range_db = 60 ;

Replace with

        volume_range_db = 30;

We can now save the file by pressing Ctrl + X then pressing Y and then Enter.

6. Now to make sure all these changes are properly loaded in, we will restart the Raspberry Pi by running the following command.

sudo reboot

Improving your Raspberry Pi AirPlay Receivers Wi-Fi Performance

1. To improve the Wi-Fi performance of your AirPlay device, you will want to disable the Raspberry Pi’s WLAN adaptor power management. This reason for this is that it can prevent Shairport from being visible on your list of Airplay devices due to it powering down the Wi-Fi adaptor.

Luckily it is easy to stop the Raspberry Pi from doing this with most adaptors. The way to do this is by modifying the network interfaces file. We can open the file by using the following command in terminal:

sudo nano /etc/network/interfaces

2. Within this file we need to locate locate and add the following text to the interfaces file. This will tell the Raspberry Pi to not manage its wireless power and will not turn it off to save power.

If you have upgraded to Raspbian stretch then wlan0 may be called something different. If you’re unsure which one is correct use the ifconfig command to see what the new name is.

Find

iface wlan0 inet manual

Add Below

        wireless-power off

We can now save the file by pressing Ctrl + X then pressing Y and then Enter.

3. Now to make sure all these changes are properly loaded in, we will restart the Raspberry Pi by running the following command.

sudo reboot

You should now hopefully have a fully working Raspberry Pi AirPlay receiver! If you have any issues or feedback feel free to drop us a line in the comment section below! If you enjoyed this tutorial be sure to check out our other projects.

The Raspberry Pi Crash Course

The Raspberry Pi Crash Course

Enter your email address below to get the

Raspberry Pi crash course delivered straight to your inbox

Please check your inbox for a confirmation email!