AirPi: DIY Airplay Speakers using Shairport and a Raspberry Pi

We have speakers in all the ground floor rooms of our house, all driven from the same amp. It’s neat but controlling the input requires going back to the amp.

Surrounded by iDevices too and with apps like iPlayer, Spotify and home share on iTunes, being able to throw audio to the speaker system had to be done. Que Airplay, however, this requires a nice Airplay amp or getting an AirPort. I then found out about Shairport, a program that emulates an AirPort’s Airplay function. With a Raspberry Pi kicking around, I had just found its new job.

Quite a lot has changed in the year since I did this and rather than try and add more updates to this, I have run through the process again and created a new tutorial.

Setting Up Arch ARM

I opted for the Arch Pi distribution for this, simply because it is my Linux of the moment and with no window manager, is perfect for a standalone device. The first thing you’re going to want to do is a system update with pacman (you’ll probably need to update pacman on first run so need to do this twice).

Next you’ll need to install the tools required to compile in Arch.

Then git to clone the Shairport repo.

Shairport has a number of dependencies so we’ll install them and there dependencies too.

Finally, alsa is required to get sound output in Arch on the RPi. Install this and then load the sound driver using modprobe.

Alsa mutes the channels by default so open the mixer and raise the volume to 0dB gain. Test the output using speaker-test.

I’m using the 3.5mm jack as an audio output and at this stage I failed to get audio. I realised that with the HDMI plugged in, audio was going through that and not through the jack (it doesn’t seem to do both at once). You need to disconnect the HDMI and reboot the RPi. If you’re connected via monitor and want 3.5mm jack, there is no option but to continue via ssh or use the phono. I was doing it all via ssh so it didn’t really matter. If you do reboot, don’t forget to reload drivers using modprobe before testing again.

update: you can change output with using amixer cset numid=3 1tomsolari.id.au ]

If all is good, save the alsa levels.

And set the sound modules and new daemons to load at startup by editing /etc/rc.conf

Probably a good idea to reboot at this stage.

Make Shairport

Make a directory called Shairport in the home folder.

Now clone the repo, cd into it and make.

All being well, Shairport should have built and you can now run it with the name ‘AirPi’.

Create daemon

18/12/12 – This may not work now due to Arch builds now using systemd. If it doesn’t, this comment thread has a solution.
Install the new build

Shairport includes a sample init file but it is not designed for Arch. Arch includes a template for creating new daemons in /usr/share/pacman/rc-script.proto, first copy to /etc/rc.d

Now edit the file using vi as mine below

Add shairport to the list of daemons in etc/rc.conf and you’re all good to go.

UPDATE 2:

I’ve since found a command to redistribute the Pi’s memory, providing less dropped audio (it doesn’t happen much anyway). By default, a certain amount is allocated to the GPU, since this is headless, we can remove that.

UPDATE 3:

Shairport has been updated to support iOS and with it now depends on perl-net-sdp. This can be installed from the AUR using these instructions

25 thoughts on “AirPi: DIY Airplay Speakers using Shairport and a Raspberry Pi”

  1. Wish I had seen this before I bought a refurb AirPort Express. I guess by the time I bought WiFi for the Pi though I would have been out almost as much.

    Great write up!

  2. I see some typos.. “alsa-util” should be “alsa-utils” and “alsa-mixer” should be “alsamixer”.. Other than that, I got a lot of problems. First one is the /etc/rc.conf .. just does not seem to work, have to run the modprob command manualy. And I get errors while trying to run the “./shairport.pl -a AirPi” command after make. “Can’t locate Net/SDP.pm”. So I tried to run “cpan install Net::SDP”, but get an error “Couldn’t untar Net-SDP-0.07.tar
    Package seems to come without Makefile.PL.” Any suggestions…

    1. Thanks, I got it running now. But still have problems with the /etc/rc.conf .. not working. Strange. Great writeup by the way :)

      1. Ok. Got it working. Seems like they dont use the /etc/rc.conf anymore.

        I ran.
        “systemctl enable avahi-daemon”

        Then I made a file “/etc/modprobe.d/default.conf”
        and added
        “services snd-bcm2835″ to the file. Reboot. And now works as expected.

        1. Oh.. the last part is wrong.

          So. Instead of making the /etc/rc.conf, I ran the command
          “systemctl enable avahi-daemon”

          Then I made a file /etc/modules-load.d/snd-bcm2835.conf and added the “snd-bcm2835″ to it.

          Thanks.

      2. Hi Guys,

        I can’t seem to get shairport.pl to automatically start when booting up. I first tried the rc.conf ‘method’ which didn’t seem to work. Then I used Stain’s instructions and added daemon.. But i can’t seem to get shairport.pl to automatically start.. Am I doing something wrong?

        When i manually start it through an ssh shell it works perfectly..

        I know it’s an old post but I hope you guys can help me.

        Thanks,

        Rik

        1. Hi Rik.

          I’ve just gone through the process using the current Arch build so I can update this post – a lot has changed. Stain only explained adding Avahi to the boot list for systemd (you should need to bother with the snd-bcm2835 module part now as it auto loads).

          With systemd you need to create a shairport.service file in /etc/systemd/system (vi /etc/systemd/system/shairport.service), containing the following:

          Finally, enable the service at startup:

          systemctl enable shairport

          This should solve your problem.

    2. I’m having the same problem with “Couldn’t untar Net-SDP-0.07.tar”, but I can’t work out how you/he fixed it. How do I install the additional dependency?

      1. You need to follow the steps on the Arch wiki, which explain installing from the AUR. In this case the ‘perl-net-spd’ package

        Here’s the link: https://wiki.archlinux.org/index.php/Arch_User_Repository

        The basic steps are:
        1. download the package (wget https://aur.archlinux.org/packages/pe/perl-net-sdp/perl-net-sdp.tar.gz should work [you’ll need pacman -S wget first])
        2. extract (tar -zxzf perl-net-sdp.tar.gz)
        3. cd perl-net-sdp
        4. makepkg
        5. pacman -Syu
        6. pacman -U perl-net-sdp.pkg.tar.xz

        And it should work. Hope that explains what you were after.

  3. hello john! does this works to stream by airpi from iphone to car stereo? is there any possibility to adapt the programing for arduino? please excuse my ignorance. Bye

    1. Yes you could do that with this and a RaspberryPi to make a airplay compatible car stereo. It’s something I considered myself but ending up just building a dock into my dashboard instead. Let me know if you do it.

      It wouldn’t be possible with an Arduino, it doesn’t have the processing power. I was going to suggest you could try a bluetooth module and do it that way instead but the digital to analogue converter is too slow for music.

    2. I am using this for my car stereo actually. I have a cheap car stereo with aux in, and USB… so I use the usb to power the Rasp, and the aux for the analog audio.. works like a charm.. I had to add a usb wifi thing, and sett it up as an Access Point. But there are guides for this. Good luck.

      1. Thanks. By tidy integration you mean you cant see the mess behind it :) Integrated mess. Next part is to make a new(old) interface for the stereo itself, make it all look a bit more 1969.

  4. Hello John!
    Just started tinkering with Arch/Raspberry Pi, but your instructions got me safely through!
    Now I can upgrade my old Marantz-Amp with “Airplay”…
    Thank you very much for your write up!
    Regards.

Leave a Reply