Introduction
For a long time I have been trying to figure out how to bring a little music to my kitchen. Since most of the products you can buy that allow for spotify connect are rather pricey and often times offer more connected services like AirPlay which I have no need for.
So I’ve decided to build a spotify connect enabled stereo-speaker on my own. Fortunately the software part is really easy: we can just use awesome raspotify!
For the hardware I’m using:
- Raspberry Pi Zero W
- Hifiberry MiniAMP (3W stereo amplifier)
- two 2.5″ 4 Ohm full-range speakers (e.g. from Visaton)
Setting up Raspbian on the Pi Zero
Since the radio will be a headless device we can use the non desktop lite version (Raspbian Download). Use balenaEtcher or a similar tool to flash the image to the SD card. Also don’t forget to setup your Wifi credentials in the boot/wpa_supplicant.conf. Assigning a static IP to your radio’s MAC on your router will also help for easier access. Additionally you’ll need to setup SSH on the Pi by creating an empty ssh file in the root of the SD card.
Adapting the config for the MiniAmp
To inform linux about the hifiberry miniamp we need to add it to the config.txt
Configure device tree overlay file
Set the hifiberry-dac as a dt overlay, for activating the device. See the knowledge base for more information. You also need to uncomment the default audio.
#dtparam=audio=on
dtoverlay=hifiberry-dac
Set up software volume control
After booting the Pi, the speakers connected to the MiniAmp should be able to play a sound.
You can test it with:
$ speaker-test -c 2
Alas! It works! But be warned at this point you can not change the volume you need to add a software volume control first.
Add the following to etc/asound.conf file:
pcm.hifiberry {
type softvol
slave.pcm "plughw:0"
control.name "Master"
control.card 0
}
pcm.!default {
type plug
slave.pcm "hifiberry"
}
And now use the device with speaker-test:
speaker-test -D hifiberry -c 2
After that you have a new ‘Master’ control in the alsamixer.
Setting up Spotify Connect
Setting up spofity connect is pretty straight forward thanks to raspotify.
Simply do the following via SSH on your pi:
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
After it is finished adapt /etc/default/raspotify with your spotify credentials and other configuration.
My config file looks something like this:
#/etc/default/raspotify -- Arguments/configuration for librespot
DEVICE_NAME="KitchenRadio"
BITRATE="160"
OPTIONS="--username $SPOTIFY_USER$ --password $SPOTIFY_PASSWD$"
VOLUME_ARGS="--enable-volume-normalisation --linear-volume --initial-volume=50"
BACKEND_ARGS="--backend alsa"
Remember to replace $SPOTIFY_USER$ and $SPOTIFY_PASSWD$ with your own credentials. After restarting the daemon by running: sudo systemctl restart raspotify.
You should see a KitchenRadio device under the spotify connect devices, indicating that we are now more or less finished with building a spotify connect enabled stereo-speaker.
Improving boot time
The last step is optional but highly recommended. By default Rasbpian waits for network while booting. You can check the spent boot times with:$ systemd-analyze blame
In my case it nearly waited 1 minute for the network. It’s fairly easy to reduce it by:
Create a file /etc/systemd/system/networking.service.d/reduce-timeout.conf with following content:
[Service] TimeoutStartSec=1
That reduced my boot up time to around 30-40s. Which is by far more acceptable than 1,5 minutes. Boot time of course also varies depending on the SD Card you are using. So a higher SD Card class will also improve the boot time.
Conclusion
In this article I showed you how to build a small spotify connect enabled stereo speaker using a raspberry pi.
There are some things that still need to be addressed like adding a button for turning the radio on and off. Or a proper enclosure to put everything in neatly.