I saw a post on Reddit about "AirPlay 2 on Linux" in the past few days, which recommended the Shairport Sync project. So I decided to upgrade the AirPlay on my Raspberry Pi at home. Those who are capable can directly read the original article, which is written in great detail.
Preparation#
-
A Linux or FreeBSD device with performance equal to or greater than Raspberry Pi 2
-
Ports 319 and 320 are not occupied
-
A speaker (preferably with a 3.5mm interface)
Installation#
First, it is recommended to update the system to the latest state, which can greatly reduce many inexplicable problems.
sudo apt-get update # Check for updates
sudo apt-get upgrade # Perform updates
Disable Wi-Fi power management#
If you are using a device with Wi-Fi connection, you need to disable power management to avoid the device entering power-saving mode and not being able to find the speaker after installation.
iwconfig wlan0 power off
Install dependencies#
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
nqptp#
nqptp is an important dependency for monitoring time in Shairport Sync and needs to be compiled and installed manually.
git clone https://github.com/mikebrady/nqptp.git # Download the project
cd nqptp # Enter the project directory
autoreconf -fi # Compile
./configure --with-systemd-startup # Configure
make # Build environment
make install # Install
After installation, nqptp needs to be started:
systemctl enable nqptp # Set to start automatically
systemctl start nqptp # Start nqptp
sps-alsa-explore#
A tool that can help us with Shairport Sync, which can list the current audio output devices intuitively and needs to be compiled and installed manually.
git clone https://github.com/mikebrady/sps-alsa-explore.git # Download the project
cd sps-alsa-explore # Enter the project directory
autoreconf -fi # Compile
./configure # Configure
make # Build environment
Connect the speaker to the Raspberry Pi, then execute ./sps-alsa-explore
in the sps-alsa-explore directory:
Record the Device Full Name: "hw:Headphones"
and Possible mixers: "Headphone"
for use in the subsequent configuration file.
#
Compile and install Shairport Sync#
git clone https://github.com/mikebrady/shairport-sync.git # Download the project
cd shairport-sync # Enter the project directory
git checkout development # Switch to the development branch
autoreconf -fi # Compile
./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2 # Configure
make -j # Build environment
make install # Install
#
Configure Shairport Sync#
The configuration file path of Shairport Sync is /etc/shairport-sync.conf
. The output device needs to be configured here. Friends familiar with vi/vim can directly configure it with sudo vi /etc/shairport-sync.conf
. Both output_device
and mixer_control_name
can be found in the results of ./sps-alsa-explore
earlier.
alsa =
{
output_device = "hw:Headphones";
mixer_control_name = "Headphone";
};
There are a lot of comments in the configuration file, and you can configure them as needed.
Start Shairport Sync#
systemctl enable shairport-sync # Set to start automatically
systemctl start shairport-sync # Start Shairport Sync
Add to HomeKit#
When adding accessories, click "Don't have a code or can't scan?" and the Home app will discover the AirPlay 2 device. Click to add it.
Issues encountered#
There is a delay when playing in a "multi-room audio system". I checked the Issues of Shairport Sync and found that not everyone has this problem. Devices connected via HDMI usually have a delay of about 100 milliseconds. The solution given in the common problems section of the documentation is to manually set a delay. There is a audio_backend_latency_offset_in_seconds
configuration item in the configuration file /etc/shairport-sync.conf
, with the unit in seconds:
If you have other problems, you can first check the documentation Troubleshooting.
User experience#
After tinkering with it for a few days, I feel that it is still in a usable state. It also allows me to experience the "multi-room audio system" function. However, it is limited to audio such as music or podcasts. The delay of AirPlay is a headache. Many video software will have audio and video synchronization problems due to lack of adaptation. Even after adapting to AirPlay, there will still be a buffering delay. But as an audio player in a "multi-room audio system", it is still very convenient.
Of course, for those who don't like tinkering, Airport Express 2 (A1392) may be a better choice. Simple configuration can make the speaker support AirPlay 2, and the price on second-hand platforms is around 150-200.