In this Raspberry Pi Spotify tutorial, we will be going through all the steps to set up the Spotify connect service. This setup is headless, so you will need to control it using another device.
Using the Raspotify software package, we can set up your Raspberry Pi so that it can work as a cheap Spotify Connect device.
Working as a Spotify Connect device allows you to easily stream songs from any Spotify app to your Raspberry Pi. This setup is an affordable way of connecting any speakers to Spotify.
In addition to showing you how to install the Spotify connect software, we will walk you through some of the basic configuration options that you can specify.
While this isn’t the full Spotify, it does allow you to easily use any other device to play music from your Raspberry Pi. It also allows you to run Spotify on your Raspberry Pi in a completely headless setup.
Below are all the bits and pieces that I made use of for this Raspberry Pi Spotify tutorial.
Raspberry Pi 2, 3 or 4
This project is all about audio, so it might be worth purchasing a USB Audio Card or a Raspberry Pi sound card. The default Raspberry Pi setup is good enough for most users.
Setting up a Raspberry Pi Spotify Connect Device
1. Our first task is to ensure everything is up to date with our operating system. It will make installing the Spotify software to our Raspberry Pi a little easier.
To do this, we will need to run the following two commands. The first will update the package list. The second command upgrades the installed packages.
sudo apt update sudo apt upgrade
2. Next, we need to make sure that both “curl” and “apt-transport-https” packages are installed to our Raspberry Pi.
Without these, we won’t be able to set up the raspotify repository on Raspbian.
Run the following command to install our needed packages.
sudo apt install -y apt-transport-https curl
3. With the packages we need installed we can go ahead and add the “raspotify” GPG key and its repository.
Without the GPG key, the apt package manager won’t be able to verify the files it’s retrieving from the repository.
You can do these two things by running the following two commands.
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
4. Now that we have the raspotify repository added to our Raspberry Pi, we can now go ahead and install the raspotify package.
This package will handle turning our Raspberry Pi into a Spotify Connect device. We can install the package by running the two commands below.
We need to rerun the update due to us adding the raspotify repository in the previous step. Without an update, the package manager won’t know what’s contained in that repository.
sudo apt update sudo apt install raspotify
5. With the “raspotify” software now installed, the software should start automatically and be ready for connections.
You should now be able to connect to your Raspberry Pi’s Spotify software. You can do this by opening up the Spotify app on your chosen device and selecting it from the “Connect to a device” menu.
Configuring the Spotify Connect Software
1. While the Raspotify software works perfectly fine right out of the box, you can make changes to its configuration.
You can use this configuration file to adjust things such as the bitrate or the device name.
Run the command below to begin modifying the “raspotify” config file.
sudo nano /etc/default/raspotify
2. Within this file, you will see multiple different options that you can configure yourself. We will go into a couple of these and explain what you can use them for.
This option defines the name for your Spotify connect service on the Raspberry Pi. You can set this to something to easier identify where the Raspberry Pi is or what the Pi is connected to.
With this option, you can specify the bitrate that you would like the device to utilize.
You can pick three different values for this option, 96 for low-quality, 160 for medium-quality or 320 for high-quality audio.
OPTIONS="--username <USERNAME> --password <PASSWORD>"
The “OPTIONS=” option allows you to specify additional options to pass through to the Spotify Connect software.
In our example, we will be passing in both a Spotify device username (<USERNAME>) and password (<PASSWORD>). By specifying these, you will be able to access the Raspberry Pi Spotify service outside the local network.
Please note that the username and password options are not what you use to log back into the account normally. You will need to retrieve these details by going to the “Set device password” screen on your Spotify account.
If the link above directs to your profile homepage and there is no option to set device password then simply enter your normal Spotify Username and password.
3. If you have made any changes, you can save the file by pressing CTRL + X then Y followed by ENTER.
4. Once you have made any changes to the raspotify configuration file, you will need to first restart the “raspotify” service by running the command below.
sudo systemctl restart raspotify
Hopefully, by now, you will now have successfully set up your headless Raspberry Pi Spotify device. It’s an excellent way to have a barebones audio player that can use any speaker that supports USB or a 3.5mm connection.
If you run into trouble following this trouble or have some feedback then please don’t hesitate to leave a comment below.