Isn't it so annoying when you are listening to music on a Bluetooth speaker, you walk out of the room, and the connection drops? Wouldn't it be nice to be able to ditch all these auxiliary cables and Bluetooth limitations? Well, there is, and it's pretty simple. Apple has developed a system that they call AirPlay, that has native support in iOS, and can be connected to from virtually any other operating system with 3rd party software. This includes Android, Windows, and probably even Linux. If you have an iPhone or Mac, you don't have to do anything! The great thins about AirPlay is that it runs over your WiFi network, so you can be anywhere in your house, and it will work, no distance limitations! Even better, your phone is no longer plugged in to the speaker if you didn't use Bluetooth! This seems like a project for everyone, so I see no reason not to move on to the next step and get started!
A couple notes: All of these pictures are either screenshots from my computer, or photos that I have taken, while I did not develop any of this software, every piece of media in this Instructable is my own.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: What You Will Need...
For this project you will need...
- One Raspberry Pi, literally any model, I use the original Pi model B and it works perfectly (If you want to use the Zero, you will need to buy an audio HAT board)
- One SD/Micro SD Card, depending on your Pi
- A power supply of some kind, preferably something like a tablet charger, which has a higher amp output.
- A speaker with 3.5mm input, or if you are an audiophile, research a HAT for your nicer speakers
- Maybe an Aux cord, if you don't already have one for your speaker
- An internet connection, Ethernet or WiFi, doesn't matter
That's it, if you have any questions on products, let me know, and head on to the next step.
Step 2: Install Some Prerequisites
So to start you will want to set up your Pi, a process I explained in detail in my NextCloud Instructable (Steps 1-4). If you don't know how to do that, go through those steps, and return here afterwards.
The first thing you will need to do is run sudo apt-get update and sudo apt-get upgrade to ensure that your Pi is fully up to date, and has the package lists downloaded for the next couple of steps.
Then you should download Git by running
- sudo apt-get install git
It may be installed with Raspbian by default, but I'm not 100% sure, it can't hurt to check right?
Next, run these commands:
- sudo apt-get install build-essential xmltoman
- sudo apt-get install autoconf automake libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev
- sudo apt-get install avahi-daemon libavahi-client-dev
- sudo apt-get install libssl-dev
- sudo apt-get install libsoxr-dev
Once that finishes, head on to the next step.
Step 3: Install ALAC
This is a little weird, and I actually have no idea where it is used, but ALAC stands for Apple Lossless Audio Codec. I assume that this is only used on Apple devices, but where it is used I have no idea. In my mind, lossless sounds pretty good, and while I'm no audiophile, if I can easily make this sound better, I will. In any case, this should make sound output much cleaner, or something like that! To install it, run these commands.
- sudo git clone https://github.com/mikebrady/alac.git
- cd alac
- sudo autoreconf -fi
- sudo ./configure
- sudo make
If there is a warning or error that you get that looks like aclocal: warning: couldn't open directory 'm4'... you can ignore it
- sudo make install
- ldconfig -v
to ensure that the library is available to the system.
Step 4: Install AirPlay Support
The big moment has finally arrived! In this step, we will install AirPlay support to our Pi! It's fairly straightforward, and if you copy the commands exactly, it will work perfectly!
Start with these:
- sudo git clone https://github.com/mikebrady/shairport-sync.git
- cd shairport-sync
- sudo autoreconf -i -f
The last command may take a while, with no apparent output, just leave it and it will run through the setup.
Next, run the following command to configure the install:
- sudo ./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-soxr --with-systemd --with-apple-alac
Finally, run the following commands to wrap up the install:
- sudo make
- getent group shairport-sync &>/dev/null || sudo groupadd -r shairport-sync >/dev/null
- getent passwd shairport-sync &> /dev/null || sudo useradd -r -M -g shairport-sync -s /usr/bin/nologin -G audio shairport-sync >/dev/null
- sudo make install
- sudo systemctl enable shairport-sync
That's it! Now we can configure our speaker.
Step 5: Configure Your Speaker
To configure your speaker, you can run
- sudo nano /etc/shairport-sync.conf
My configuration will work with every system that uses the standard 3.5mm headphone jack on the Raspberry Pi for output. It essentially sets the correct volume range and names the speaker. If you want to use those settings, (the volume range correction is nice) then delete all the text from the configuration file and paste the text from the file you can download in this step into it.
To setup this volume range, you will need to add the following at the bottom of /boot/config.txt. To do this, run:
- sudo nano /boot/config.txt
And paste this line at the bottom:
That's it! You're done, you can now reboot to start the speaker, or start it manually by typing:
- sudo service shairport-sync start
Step 6: Additional Info
This setup should work for everyone, in the event that it doesn't work, all of these are on GitHub, so it may help to read through the documentation. Below are the links to the
ALAC Documentation: https://github.com/mikebrady/alac
Shairport-Sync Documentation: https://github.com/mikebrady/shairport-sync
That's it! I hope that this was pretty easy for everyone, and I think that it is a perfect candidate for the IOT contest, so I entered it. If you liked this project, you should give it a vote, I'd really appreciate it! And I guess if you didn't like it, another vote can't hurt, maybe the next Instructable I publish will be better if you vote for me! Anyway, thanks a lot! Good luck with your new speaker! If you're really ambitious. you could even try to set up some whole house audio with instructions at this link.
One more thing, in the first photo, I have a case for my Raspberry Pi and the speaker. It's 3D printed, totally not perfect, but for something that you will want to hide (who wants to see all those wires!!), it's perfect. If you want the files, I'll attach them below. I have access to printers at school, so it's pretty easy, but I just wanted to add them just in case anybody wanted them. The case is for a Raspberry Pi 1 Model B, and should fit a 60-66mm diameter speaker, although you may have to sand the holes so you can plug everything in! I'm not promising legendary design, but it's OK!
Participated in the
Internet of Things Contest 2017