This content originally appeared on DEV Community and was authored by Henry Lim
Got a mini-PC, SBC, or Raspberry Pi speaker lying around? You can pair it with a Bluetooth speaker to create your own AirPlay receiver, letting you stream music from any Apple device. This guide uses DietPi and Shairport Sync to build a dedicated, budget-friendly audio streamer.
What You’ll Need
- A Linux-compatible computer (like a mini-PC, SBC, or Raspberry Pi)
- A microSD card with DietPi installed
- A Bluetooth adapter (if your computer doesn’t have built-in Bluetooth, a simple one like the TP-Link UB400 will work)
- A Bluetooth speaker
A Note on DietPi
While you could do this on any Linux distribution like Ubuntu or Debian, DietPi is a great choice because it’s lightweight and its user-friendly command-line interface makes installing software and configuring your device much simpler.
1. Install the Software
First, get your computer ready. After installing DietPi, use its built-in software installer to get the two main programs we need.
- Open the DietPi software menu:
dietpi-software
. - Install Shairport Sync (AirPlay 2) (
#37
) and ALSA (#5
).
2. Enable Bluetooth and Pair
Next, you need to enable Bluetooth on the computer and pair it with your speaker.
- Enable Bluetooth in the DietPi configuration menu:
dietpi-config
-> Advanced Options -> Bluetooth -> [On]. - Install the necessary utilities:
apt install bluez-alsa-utils
. - Now, use
bluetoothctl
to connect your computer to the speaker. Be sure to replace the example MAC address (02:50:41:A4:DE:6B
) with your speaker’s actual address.bluetoothctl
power on
scan on
- Wait for your Bluetooth speaker’s MAC address to appear in the list. Note down the address and then turn off the scan.
scan off
trust 02:50:41:A4:DE:6B
connect 02:50:41:A4:DE:6B
- For a cleaner setup, you can rename your computer’s Bluetooth broadcast name.
system-alias AirPlay # Rename it to "AirPlay"
3. Configure Audio Routing
To ensure audio is sent through Bluetooth, we’ll edit the ALSA configuration file.
- Open the file:
nano /etc/asound.conf
. -
Replace the entire content with the following code. This tells ALSA to route all default audio to the Bluetooth speaker.
pcm.btreceiver { type plug slave.pcm { type bluealsa device "02:50:41:A4:DE:6B" profile "a2dp" } hint { show on description "Bluetooth Receiver" } } pcm.!default { type plug slave.pcm "btreceiver" }
4. Automate the Connection
To make this setup seamless, we’ll create a script that automatically connects to the speaker whenever AirPlay starts.
- Create the script file:
nano /root/shairport-sync-connect.sh
. -
Add this simple script to the file:
echo "Connecting to Bluetooth Speaker ..." bluetoothctl connect "02:50:41:A4:DE:6B" sleep 3 exit 0
Make the script executable:
chmod +x /root/shairport-sync-connect.sh
.
5. Finalize Shairport Sync Settings
Finally, we’ll update the Shairport Sync configuration to use the new script and give your AirPlay device a friendly name.
- Open the configuration file:
nano /usr/local/etc/shairport-sync.conf
. - Find and change these three lines:
general.name = "Bluetooth Speaker"
sessioncontrol.run_this_before_entering_active_state = "/root/shairport-sync-connect.sh"
sessioncontrol.wait_for_completion = "yes"
6. Restart the Service
To apply the changes you just made, you need to restart the Shairport Sync service.
Run the following command to restart the service: systemctl restart shairport-sync
That’s it! Now your computer will appear as an AirPlay speaker on your Apple devices, ready to stream music. Enjoy your new, custom-built sound system!
This content originally appeared on DEV Community and was authored by Henry Lim