Wouldn’t it be cool if you can stream your music directly from your iPhone to your speakers or audio receiver system?
This is in-fact possible using a Raspberry Pi connected via a audio cable to your receiver and connected via WiFi and AirPlay to your iPhone. It all sounds pretty complex but it is in fact not hard to setup at all.
Before we get started – please note that this guide is only for audio – we will not be able to steam videos to your tv at this time.
Prerequisites & Equipment
You are going to need the following:
- A Raspberry Pi (Buy here)
- A 3.5mm Stereo Jack cable to connect the Raspberry Pi to your receiver
- A USB WiFi Adapter (Unless you want to run a network cable)
- I use the Edimax – Wireless 802.11b/g/n nano USB adapter – its small and cheap!
- A SD Card flashed with the Raspbian OS (Here is a guide if you need)
- Access to the Raspberry either via keyboard and a monitor or remotely
If you need any help connecting your Raspberry Pi to your WiFi network you can use the guide here.
Step 1 – Making sure the audio output work
Connect all the cables such that your Raspberry Pi is powered and connected to your receiver or stereo.
Turn your receiver or stereo on and select the correct input – because we are going to check that the sound from your Raspberry Pi comes out of your speakers.
From the Raspberry Pi command line we can access the audio mixer by running the command:
Here make sure that your signal is not muted (press ‘m’ to un-mute if it is) – you can also use arrow-up and arrow-down turn the volume up and down. Press ‘ESC’ to exit the mixer.
Next we can test the output by running:
speaker-test -t sine
If you hear a tone in your speaker you are good to go. If not verify you are using the correct input on your receiver, if you are still not hearing anything try turning the volume up in the alsamixer.
Before proceeding we need to change the ‘also’ configuration slightly – open the configuration file with the following command:
sudo nano /usr/share/alsa/alsa.conf
Use pagedown to scroll down a few pages till you see a line saying:
Change this line to:
Save the file (Ctrl+o – enter) and exit nano (Ctrl+x). We are now ready to install the software needed to stream audio to our Raspberry Pi.
Step 2 – Install the Shairport AirPlay Software
The Shairport AirPlay software is the software we need in order to turn our Raspberry Pi into a AirPlay receiver. It will emulate an AirPlay endpoint such that you can select it as output from iTunes or your iPad or iPhone.
You are going to need a bit of time to complete this step ~30 minutes should do it – so make sure you have that available before proceeding.
Before installing the shairport airplay software we want to install a number of modules needed to compile it. Run the following commands to install the modules:
sudo apt-get install libao-dev libssl-dev git avahi-utils libwww-perl sudo apt-get install libcrypt-openssl-rsa-perl libio-socket-inet6-perl libmodule-build-perl
After installing the modules we want to create a Projects folder to put the Shairplay files in – this can be done using the following commands:
mkdir projects cd projects mkdir airplay-audio-project cd airplay-audio-project
Once we are in the project folder we want install an extra module that can make Shairport work with IO6 devices. You don’t need it for older Apple devices, but I recommend installing it so you wont run into problems when upgrading your Apple products in the future.
Installing the extra module can be done with the following commands:
git clone https://github.com/njh/perl-net-sdp.git cd perl-net-sdp perl Build.PL ./Build ./Build test sudo ./Build install cd ..
Next we want to checkout the latest version of the Shairport software and compile it onto our Raspberry Pi. Use the following commands to do so:
git clone https://github.com/abrasive/shairport.git cd shairport make
Now we can actually test the software to see if it works. Run the Shairport Airport software on the Raspberry Pi with the following command:
./shairport -a RaspberryPi
If you receive a “Unknown PCM cards.pcm.front” make sure you made the configuration file change explained late in the last step.
Once we have verified it works exit the program (Ctrl+c) – and install Shairport Airport onto our Raspberry Pi with the command:
sudo make install
The last step is to make sure that it starts automatically when the Raspberry Pi boots up. This can be done with the following commands:
sudo cp shairport.init.sample /etc/init.d/shairport sudo chmod +x /etc/init.d/shairport sudo update-rc.d shairport defaults
Now the Shaiport software will start when your Raspberry Pi is powered up. Its name will be ShairPort on iPhone, if you want to change it you can do so by editing the /etc/init.d/shairport file – there is a ‘name’ parameter you can edit.
Edit the file with the following command:
sudo nano /etc/init.d/shairport
One warning – do not use spaces in your name – it may cause problems when starting the Shairport software.
Reboot your Raspberry Pi (you can use the command “sudo shutdown -r now“) and you now have your own AirPlay speakers using a Raspberry Pi!
You may find that the Raspberry Pi onboard soundcard is not the best. If this is the case you can buy an external USB based soundcard if you want better sound.
Here is a video of the project in action: