Build AirPlay 2 audio receiver on a Linux computer with Shairport-sync.
Do you have an old laptop lying down somewhere else?
Are you also an iPhone, iPad, or Mac user?
I found a way to repurpose my old laptop into an AirPlay receiver or speaker.
A GitHub repository called Shairport-sync can help us to enable AirPlay capability to almost any Linux computer(Raspberry Pi too). Shairport-sync is a project that emulates the Apple AirPort Express router for audio streaming purposes.
Since I got an old laptop that runs as my home server using Lubuntu OS. Also, the laptop's built-in speaker sound quality is not good, but still capable play some Lo-fi songs as background music. Additionally, the laptop can be used as an AirPlay receiver. The laptop's audio jack can output the audio received from AirPlay and output the audio to an external speaker.
Shairport-sync supports AirPlay 1 and limited functions AirPlay 2. Here I'm installing the AirPlay 2, and the limitation can refer back to the repository document.
Let's get started.
Video
Install tools and libraries for Shairport-sync.
The first step is always to update and upgrade the package and dependency on our system.
$ sudo apt update $ sudo apt upgrade
Now, we need to install all the necessary packages.
$ sudo apt install --no-install-recommends build-essential git xxd xmltoman 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
Disable Wi-Fi Power Management.
If your device uses Wi-Fi, please disable the Wi-Fi power management function. When the Wi-Fi connection is inactive, it will bring the Wi-Fi system to low-power mode. In this mode, it may not respond to the AirPlay request.
$ sudo iwconfig wlan0 power off
My laptop Wi-Fi system doesn't support this function, so I can skip this step.
Install NQPTP
NQPTP is a companion app to Shairport-sync, so we also need to install this app to make Shairport-sync work.
$ git clone https://github.com/mikebrady/nqptp.git $ cd nqptp $ autoreconf -fi $ ./configure --with-systemd-startup $ make $ sudo make install
Next, we set the NQPTP service to start automatically at the next system restart and start it now.
# systemctl enable nqptp # systemctl start nqptp
Install Shairport-sync
Here we start to clone the Shairport-sync repository and check out the development branch(for AirPlay2). The autoreconf step may take a while to process.
$ git clone https://github.com/mikebrady/shairport-sync.git $ cd shairport-sync $ git checkout development $ autoreconf -fi $ ./configure --sysconfdir=/etc --with-alsa \ --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2 $ make -j $ sudo make install
After the installation is done, we can proceed to configure the Shairport-sync.
Configure Shairport-sync
You can find the configuration file in this location. To edit this file, you can use this command:
$ nano /etc/shairport-sync.conf
The configuration file already has very comprehensive comments explaining every field. I only change the device name and leave the other as default.
general = { name = "Lenovo-G475-AirPlay2-Adapter"; };
Use ctrl + o
to save the file and ctrl + x
to exit
the text editor.
Enable and start the Shairport-sync service
After the file is saved, we need to enable the Shairport-sync service to start automatically on the next system startup.
$ sudo systemctl enable shairport-sync
Again, we can start the service right now.
$ sudo systemctl start shairport-sync
Demonstration
Here I use my iPhone to stream music to my laptop using AirPlay 2.
Furthermore, I also stream music to other AirPlay 2-enabled devices(My Hackintosh).
Integrate the Shairport-sync into the Home app.
Go to the Home app, and click the top right + button.
Click the "Add Accessory".
Click "More options...".
Select the Shairport-sync installed device.