Streaming audio from a Pi to a Bluetooth speaker, with Spotify Connect
Published on 26 November 2021
Very raw notes on getting a Pi to appear as a Spotify Connect speaker, and stream to a bluetooth speaker. Might not work for your set-up, sorry.
Flash the operating system
- I used Raspberry Pi OS Lite Buster (not the latest, Bullseye).
- Enabled ssh
- Connected to my wifi network
Update the OS packages
sudo apt update && sudo apt upgrade -y && sudo reboot
Auto-connect Bluetooth audio
Using: https://github.com/bablokb/pi-btaudio
sudo apt-get install git -y
git clone https://github.com/bablokb/pi-btaudio
cd pi-btaudio
sudo tools/install
Pair speaker:
$ sudo bluetoothctl
# scan on
[NEW] Device 00:02:3C:6B:63:48 Creative MUVO 2c
# pair 00:02:3C:6B:63:48
[CHG] Device 00:02:3C:6B:63:48 Paired: yes
Pairing successful
# trust 00:02:3C:6B:63:48
[CHG] Device 00:02:3C:6B:63:48 Trusted: yes
Changing 00:02:3C:6B:63:48 trust succeeded
[CHG] Device 00:02:3C:6B:63:48 ServicesResolved: no
[CHG] Device 00:02:3C:6B:63:48 Connected: no
# connect 00:02:3C:6B:63:48
Attempting to connect to 00:02:3C:6B:63:48
[CHG] Device 00:02:3C:6B:63:48 Connected: yes
# quit
sudo nano /etc/asound.conf
## Add MAC address above to line:
defaults.bluealsa.device "00:02:3C:6B:63:48"
Test autoconnect:
aplay -vv /usr/share/sounds/alsa/Front_Center.wav
Should play sound out of the speaker 🔊.
Spotify Connect target
Using: https://dtcooper.github.io/raspotify/
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
Fix for crashing issue (should be fixed in raspotify 0.31.2)
Connecting to the speaker in Spotify would crash and not work because of this config problem. This is going to be fixed very soon and the next part won't be needed.
sudo systemctl edit --full raspotify
Add AF_UNIX
to RestrictAddressFamilies
:
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
Save the file and run:
sudo systemctl daemon-reload && sudo systemctl restart raspotify
Enjoy
The speaker should now appear in the Spotify app. You should be able to play music to it. Turning the speaker off/on should automatically pair it with the Pi.
Massive shout-out to this blog post, which has a lot of info about bluetooth on the Raspberry Pi.