Setting up Spotify Connect on the Raspberry Pi
First update your Pi’s OS:
sudo apt update sudo apt upgrade
Install ‘curl’ and ‘apt-transport-https’
sudo apt install -y apt-transport-https curl
Add the raspotify repository and the GPG key:
curl -sSL https://dtcooper.github.io/raspotify/key.asc | sudo apt-key add -v - echo 'deb https://dtcooper.github.io/raspotify raspotify main' | sudo tee /etc/apt/sources.list.d/raspotify.list
Install ‘raspotify’:
sudo apt update sudo apt install raspotify
You should now be able to go into the Spotify app on your phone or tablet and select your pi from the device choices.
Tweaking:
You can change your Pi’s device name and the bit rate of the stream by editing the configuration file:
sudo nano /etc/default/raspotify
Look for the device name and bitrate strings and make any desired edits. Then save and restart the raspotify service:
DEVICE_NAME="raspotify" BITRATE="160"
sudo systemctl daemon-reload sudo systemctl restart raspotify
Troubleshooting:
raspotify – no sound even though phone is connected to Pi
Source for further investigation: https://github.com/dtcooper/raspotify/issues/31
Use aplay -l to see devices. Sample output:
pi@lab9:~ $ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1] Subdevices: 3/4 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones] Subdevices: 4/4 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 card 2: sndrpihifiberry [snd_rpi_hifiberry_dacplusadc], device 0: HiFiBerry DAC+ADC HiFi multicodec-0 [HiFiBerry DAC+ADC HiFi multicodec-0] Subdevices: 1/1 Subdevice #0: subdevice #0
Edit the raspotify configuration:
sudo nano /lib/systemd/system/raspotify.service
Find the “ExecStart” line and add the device.
In this case (example above), desired device is sndrpihifiberry.
Card is 2 and Device is 0. Use “–device hw:2,0” in configuration.
ExecStart=/usr/bin/librespot --name ${DEVICE_NAME} $BACKEND_ARGS --bitrate ${BITRATE} $CACHE_ARGS $VOLUME_ARGS $OPTIONS --device hw:2,0
Restart the service:
sudo systemctl daemon-reload sudo systemctl restart raspotify