Pi

How to Set Up Your Raspberry Pi as an AirPlay Receiver

The Raspberry Pi is a great little computer that provides a device to do little projects on.

In this tutorial, I’ll show you how to set up a Raspberry Pi to be used as an AirPlay receiver so you can stream audio from any iOS device, iTunes or compatible AirPlay software.

Requirements

You’re going to need a few things before we get started.

  • Raspberry Pi (I’m using the Raspbian OS]
  • 4GB (Or larger SD card)
  • Power Adapter (Micro USB)
  • Display & Keyboard (or set up SSH)
  • Speakers
  • Ethernet Cable

Install Updates

We want to make sure that the Pi’s software is all up to date by entering the following into the command line:

sudo apt-get update && sudo apt-get upgrade

This lets us run two commands one after another. The first, sudo apt-get update , checks for any new software packages. The second, sudo apt-get upgrade, downloads and installs the software packages that are available.

Installing Additional Software

Now that the Raspberry Pi is up to date, we need to install additional software that isn’t included as standard. This software will help us set up the AirPlay receiver:

  • avahi-utils
  • build-essential
  • chkconfig
  • git
  • libao-dev
  • libavahi-client-dev
  • libcrypt-openssl-rsa-perl
  • libio-socket-inet6-perl
  • libssl-dev
  • libwww-perl
  • pkg-config

In order to continue we will need to install those software packages, so let’s install them.

Installing Software Packages

To install the software packages, we’re going to use one huge command:

sudo apt-get install avahi-utils build-essential chkconfig git libao-dev libavahi-client-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libssl-dev libwww-perl pkg-config

As soon as you enter that Raspbian will begin to download all of the files necessary.

ShairPort

Now we will need to download a piece of software called ShairPort. This is the core piece of software that will allow us to stream audio to our Raspberry Pi. Just to make sure we’re at the right place in the directories type cd into the command line and we will be ready to continue.

We can now use one of the pieces of software that we previously installed called git to download ShairPort from GitHub.

git clone -b 1.0-dev git://github.com/abrasive/shairport.git

This will then download the ShairPort files that we need, so once it has completed the download type the following into your command line:

cd shairport

This will take you to the ShairPort folder which you just downloaded. Now we are going to prepare ShairPoint for install and then we will install it.

sudo ./configure && sudo make && sudo make install

After that has completed ShairPort will be ready to go.

Starting ShairPort

To start ShairPort, enter the following command:

shairport -a ‘Not Apple Pi’

This will start the ShairPort server. I decided to call it Not Apple Pi but you can call it whatever you like. Our Raspberry Pi will then state that it’s “listening for connections” which means it’s ready to go.

not-apple-pi

I’ve opened up the AirPlay menu on my iPod, and you can now see that the Raspberry Pi, titled Not Apple Pi is in the list. To test it out, simply start streaming some audio to it and plug in your speakers or headphones.

If you have HDMI and a headphone jack plugged in the Raspberry Pi will play through the HDMI instead, so unplug the HDMI and reboot the Raspberry Pi, then run ShairPort again.

Adjusting the Volume

Hopefully you should have some audio playing through your Raspberry Pi.

If the audio is a little quiet you can boost it. Firstly pressing Ctrl+C will stop ShairPort and then you can enter the following command:

alsamixer

Then using the up and down arrows you can adjust the volume levels. I’d recommend around 75-80, otherwise your audio may become distorted.

alsa

Press Esc to save your changes and quit and then run the ShairPort starting command again.

Finishing Off

The quality through the headphone jack is not great but acceptable, and you get better quality through HDMI. But it’s a cool thing that you can set up in just a few minutes so you can stream audio to your Pi.

Video Tutorial

Richard Waterworth

Richard has been interested in technology from a young age. He started this blog to share his opinions on technology with the world.

  • Paul Hein

    And how to autostart the service?

    • http://richardwaterworth.me.uk/ Richard Waterworth

      I’m not sure how to autostart the service.

    • Luke Curtis

      cd ~
      sudo nano .bashrc
      on the last line of the file add the following text
      .//shairport
      if that doesnt work, try it without the dot at the beginning. (not on pi atm so can’t check)
      as long as terminal boots up on start it will run.

      any issues just tweet me @ilukecurtis – i got this working yesterday

      • Paul Hein

        I found already a solution. For Debian/Ubuntu/Raspbian, you go into the folder scripts, into debian, and copy everything here into the respective folders in /etc/ .
        After that just a sudo update-rc.d shairport defaults and a sudo service shairport start and it should be running nice and smoothly.

  • Marcel Bax

    Hi,

    HDMI sound is not working for me, if I set “amixer cset numid=3 1″ audio is played via headphones.
    If I set “amixer cset numid=3 2″ (HDMI) there is no audio!?

    any solutions?