Make your Raspberry Pi show up as a Spotify Connect device able to stream audio from Spotify and be controlled from your phone. To accomplish this we’ll be using raspotify (docs) which is a Raspberry Pi friendly wrapper around librespot (docs), a Spotify client.

Install Raspotify

The below command is all that is nessesary to install raspotify; however, check the official install instructions to double-check for updates to this command:

sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

After the above command finishes, your Raspberry Pi should be available via the Spotify app as raspotify.

If you run into installation issues, or if Raspotify isn’t showing up in your list of Spotify Connect devices, see the debugging steps at the end of this article for some of the steps I took.

For additional setup, check the official Raspotify wiki, or read on.

Customizing the Raspotify device name & bitrate

You can customize settings such as the bitrate and device name by modifying the config file found here:

sudo nano /etc/default/raspotify

I recommend adding OPTIONS="--zeroconf-port 44677" to the config file to force raspotify to start librespot (the Spotify Connect client) on the port of your choice (in the above example 44677), otherwise librespot will start on a random port each time raspotify restarts which is unpredictable if you’re using the monitoring dashboard.

After you make any modifications, make sure to save the file and restart Raspotify or your changes will not be reflected:

sudo systemctl restart raspotify

You can check the status of raspotify using the below command

sudo systemctl status raspotify

Enable a USB audio device on the Raspberry Pi

The reason I wanted to install Spotify Connect on my Raspberry Pi was so that I could output audio to my DAC and into my speaker system. Other devices with built in Spotify connect (e.g. Roku, Smart TVs) will force you to use an analog 3.5mm audio output, so this solution is quite the quality upgrade. To do this we need to tell the Raspberry Pi to use its USB ports as the audio out instead of the 3.5mm analog audio jack.


The USB audio device (DAC) I use and recommend: Schiit Modi (or a cheaper option). I wouldn’t recommend going much cheaper than budget option I linked unless there is a non-audio-quality-based reason you need to output audio via USB, at that point you’re probably fine with the built-in 3.5mm audio output.


First plug you USB DAC into the Pi and check if it was detected and successfully registered with the system. The command below will list audio devices registered with the system:

aplay -l

Note the card number of your device (ex. output might be: card 1: ODACrevB). If you don’t see your USB DAC in the output of the aplay command, try running lsusb or dmesg to see if your pi is actually detecting it at all.

Next, you need to set the USB DAC as the default audio device. To do this, edit the following config file

sudo nano /usr/share/alsa/alsa.conf

Scroll down until you find the following two lines and replace the 0 with the card number of your device (in my case it was 1):

defaults.ctl.card 0
defaults.pcm.card 0

That’s it. You might need to restart any services currently using the sound output or restart the pi altogether to get audio to stream to your USB DAC. Once everything is working, you can customize your pi’s sound settings with the following command:

alsamixer

Additional information about USB audio devices in this article

Debugging

If Raspotify not showing up in Spotify’s list of devices, or if you had installation errors try the below debugging steps.

Make sure you install latest version of librespot

If you recive an error, or if Raspotify isn’t showing up in your list of devices, one debugging step is to install the latest version of the librespot binary (the CLI library that raspian uses as the Spotify Connect client).

Note: librespot is built with rust, so you need rust and cargo to compile the source code (sudo apt install rustc cargo)

In a temp folder download the latest source code and compile it

git clone https://github.com/librespot-org/librespot.git
cd librespot/
cargo build --release --no-default-features --features alsa-backend

Remove the old librespot binary and replace it with the new one

sudo rm /usr/bin/librespot
mv target/release/librespot /usr/bin/librespot

Additional documentation on compiling librespot.

I’m hearing audio clicking or having audio issues with Raspotify

Follow the “The audio output buzzes a few seconds after audio stops!” section of the raspotify wiki to prevent clicks.

Additional troubleshooting

The above two debugging steps represent the only issues I ran into when installing Raspotify; however, the official Raspotify GitHub wiki has a more exhaustive list of troubleshooting steps you can try.