This post has been updated with new build instructions.
Below you will find instructions on how to build the Preconfigured Airplay speaker (Shairport) image. You may also find a thread about this build in the Raspberry Pi Forums.
The image assumes you’re starting out with the the standard Raspbian install. If you are starting out with Raspbmc as a base, read this additional information when you get stuck.
This tutorial will be run as root. Log in using the pi user and then do:
apt-get update && apt-get upgrade
Make sure to run expand_rootfs and reboot, otherwise you will run out of free space!
apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git chkconfig libssl-dev libavahi-client-dev libasound2-dev pcregrep pgrep
In case you are having issues with the prequisites, there is som help here:
Make sure to update the firmware, this will avoid popping noise when starting the speaker
git clone git://github.com/Hexxeh/rpi-update.git
We need to change the ALSA config slightly, otherwise Shairport will output an error – “Unknown PCM cards.pcm.front”
Change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”
We need to fix issues with avahi-daemon, which will return the error “avahi-daemon disabled because there is a .local domain” on many networks:
The solution is to modify the avahi-daemon init.d script.
Find the line starting witH DISABLE_TAG and change the filename to an invalid file, like this:
(Note DISABLED at the end)
Restart avahi-daemon and make sure it is run on boot
service avahi-daemon restart
chkconfig avahi-daemon on
Source (original issue)
Now we’re going to test the audio:
You should hear audio through your speakers. Audio file credit
git clone -b 1.0-dev git://github.com/abrasive/shairport.git
Start it to see if everything is working:
./shairport -a 'Shairport 1'
Volume levels are a bit low, raise the volume with the following command:
Keep it at about 85. (0 or negative gain). Going close to 100 will distort the audio output.
Autostarting Shairport on boot
We can use the included boot script, but we need to fix some issues with the script related to ALSA permissions and install paths.
Use this script, which changes the running user (for ALSA permissions) and removes some faulty install detection:
Download the modified startup script here. (GitHub gist)
Paste the contents of the script above in a new file:
Toggle the script on and off again. (We will see why below)
chkconfig shairport on
chkconfig shairport off
Starting shairport on boot turns out to be very tricky – sometimes shairport starts before avahi-daemon, which makes shairport fail.
To fix this we make a tiny watchdog script that makes sure shairport is always running.
Create a new text file named shairport-watchdog.sh in /root:
Paste the following:
# find service pids
#if we get no pids, service is not running
if [ $? -ne 0 ]
service shairport start
echo "shairport started or restarted."
Edit the file /etc/crontab and add the following line:
* * * * * root /bin/sh /root/shairport-watchdog.sh > /dev/null
The script will now check if shaiport is running every minute, and if not start it. This has the added benefit of restarting shairport if it crashes.
If you know of a cleaner way to declare avahi-daemon dependency in the init.d script for shairport, drop me a comment! There is an ongoing thread on Github about that
here. Shairport Issues have been removed from GitHub
Some final cleanup:
chown -R pi:pi /home/pi/
And we’re done!
USB Sound Cards
Check out this tutorial, which has instructions for using Shairport with USB sound cards.
Setting up Wifi
Although it’s not provided in the image, it is possible to set it up with conventional means. Link