Adding Spotify / Airplay can it coexist

I just made my first attempt at adding Spotify Connect to RoPieee (which I’ve been using for a few months now) and have to say it was deceivingly easy. I have two RoPieee end points now and while the process was generally the same for both, I did run into a bit of trouble on the second.

Backstory

First, when looking into what to use I came across Raspotify. It is clearly targeted at Raspbian and it’s Debian base so that didn’t appear promising, but it did give a good overview… that it was essentially a small wrapper of librespot. In searching about librespot, I came across spotifyd - a small wrapper (written in rust) around the more library-centric librespot (also rust) project to turn it into an all around easier-to-use binary. I checked it out to see how much effort might be involved, but to my surprise… it just worked!

Second, I doubt I can provide much support if you decide to take this route as I’m sure there’s quite a few hardware variables out there and I’m no ALSA expert, but hopefully my two examples will be enough to point people in the right direction.

Instructions:

  • Head over to the spotifyd releases page on Github and copy the link to the latest armv6 release.
  • SSH to your RoPieee box (out of scope, but simply the following on Mac/Linux):
    • ssh root@192.168.your.ip
    • password is root
# use the link you copied from the above Github releases page - the below link is up to date as of the time of this post
wget https://github.com/Spotifyd/spotifyd/releases/download/0.2.11/spotifyd-2019-06-19-armv6.zip
# if the below pacman command fails, just try it again
pacman -S unzip
# unzip the file you downloaded
# probably easiest to use tab-completion - simply type: unzip spot<Tab key>
unzip spotifyd-2019-06-19-armv6.zip
# move the spotifyd binary into place
mv spotifyd /usr/local/bin/
# create a SystemD unit file, file contents listed separately below
# I used vi for this as that was the only editor available, but since that
# has a steep learning curve, definitely feel free to install nano with:
# pacmac -S nano
vi /etc/systemd/system/spotifyd.service
# create spotifyd config
# same as above regarding editor of choice
vi /etc/spotifyd.conf
# enable spotifyd service so it starts on boot
systemctl enable spotifyd
# start the service now!
systemctl start spotifyd

SystemD service unit file contents: /etc/systemd/system/spotifyd.service

[Unit]
Description=A spotify playing daemon
Documentation=https://github.com/Spotifyd/spotifyd
Wants=sound.target
After=sound.target
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/local/bin/spotifyd --no-daemon
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

spotifyd config: /etc/spotifyd.conf
Check the README on spotifyd’s Github page (github dot com/Spotifyd/spotifyd) for more details about this config file and all it’s options.

[global]
backend = alsa
volume-control = alsa
device_name = Your_Device_Name     # can NOT contain spaces
bitrate = 320
volume-normalisation = false
initial-volume = 100
disable-audio-cache = true

The above simple config “just worked” for my Raspberry Pi 4 running RoPieee (beta) connected to a USB DAC. On my second attempt at this on a Raspberry Pi 3 B+ running RoPieee (stable) with a Allo DigiOne HAT, I struggled to get audio. After plenty of trial and error, I wound up adding the below to my /etc/spotifyd.conf above in order to get this to work:

device = hw:1

So how did I arrive at that value? Here is the output from a couple of commands, some device names I tried (that failed), and what that hw:1 even means. Wikipedia even has a good primer on ALSA concepts (wikipedia dot org/wiki/Advanced_Linux_Sound_Architecture#Concepts).

[root@ropieee ~]# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=sndallodigione
    snd_allo_digione, 
    Default Audio Device
iec958:CARD=sndallodigione,DEV=0
    snd_allo_digione, 
    IEC958 (S/PDIF) Digital Audio Output

From the above output I tried names like:

  • sysdefault
  • sysdefault:CARD=sndallodigione
  • sysdefault:sndallodigione
  • iec958
  • iec958:sndallodigione
  • iec958:sndallodigione,0
  • many I’ve forgotten

However, based on reading the ALSA project’s wiki entry on device names (alsa-project dot org/wiki/DeviceNames) I was able to piece together hw:1 from the below output:

[root@ropieee ~]# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: sndallodigione [snd_allo_digione], device 0: Allo DigiOne HiFi wm8804-spdif-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I even tried hw:1,0 which failed, but hw:1 for “use hardware interface for card 1” worked. The ALSA wiki suggests avoiding this for anything besides mono output, but I clearly get stereo output, though my present DAC doesn’t give me any indication as to what format.

Apologies for the long first post, but hopefully others will find this useful! I’ve only been using it for a couple of days so I have no idea on long-term stability (something RoPieee excels at for Roon!), but it’s been working well so far.

Edited to remove helpful links since I’m a new user which limits me to two.

3 Likes