11 December 2020

Setting up Spotifyd with pulseaudio

by Zubair Abid

Update: 2020-12-13 - Future releases of spotifyd might require quoted strings in the configuration file. The master branch already requires such, hence the instructions in the README, but that is not the one available in the various repositories. If and when the update hits, I will probably add a new post with the updated configuration, if it turns out to be necessary.

Update: 2021-02-06 - Yep.

I can’t seem to find any up-to-date setups for this, and have had to endure some degree of trial and error. Documenting it for myself, and in case others care.

Basic information

I’m writing this guide for a Linux user who wants to run it with the pulseaudio backend. A Spotify Premium account is needed for this to work. This does not cover an installation guide, just how to set it up for pulseaudio.

▶ spotifyd --version
spotifyd 0.2.24

Why?

Electron.

Setting up Spotifyd

Installing

So the first task is to setup spotifyd on Linux. Installing is easy – check their provided guide to find the instructions for your specific distribution. I used pacman -Syu spotifyd on mine. From what I understand, the pre-installed binaries for your distribution might not be compiled to work with pulseaudio, so you will have to either get the full variant, or compile it yourself with the necessary flags. This has not proven to be a problem on Arch-based systems in my limited testing of one (1) device.

Configuration

Note, 2021-02-06: This is an updated configuration. To see the older version of this page, check this commit.

The base configuration can be copied from the instructions. Some changes to note:

Overall, this is what the configuration file should look like (stripped of comments)

# The username can be gotten from your Accounts page. It's the convoluted string
# of characters, not the Email ID.
username = "USERNAME"
# Pick any of the password store methods. 

backend = "pulseaudio"
volume_controller = "alsa"

# The device name can't have spaces. The device type has only cosmetic changes.
device_name = "PICKANAME"
device_type = "computer"

bitrate = 320

# create the directory. I chose not to keep a cache, but you might.
cache_path = "/home/USER/.cache/spotifyd"
no_audio_cache = true

# Disabling normalisation works better for me
# And for some reason, on my machine "0" corresponds to 38%
initial_volume = "0"
volume_normalisation = false
normalisation_pregain = -10

zeroconf_port = 4444

Why am I disabling volume normalisation?

Whatever volume normalisation spotifyd uses internally seems to be, honestly, quiet trash 1. Where I normally listen to music at 24% volume, I need to raise it to around 50% to get anywhere close to the same loudness with normalisation enabled, and the audio is compressed too.

Starting spotifyd, and a little bit of Systemd

I have opted to start it as a user service, using systemctl. You can choose to run it with spotifyd --no-daemon if you so wish.

I created a file called spotifyd.service in .config/systemd/user/default.target.wants. I’m like, 90% sure you need to put it in the parent folder, but this seems to work fine for now – I guess you just don’t get to disable the daemon. The file is sourced from the github link. As of the time of writing this, the contents are:

[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/bin/spotifyd --no-daemon
Restart=always
RestartSec=12

[Install]
WantedBy=default.target

Check that your service is running with systemctl status --user spotifyd.service. In fact, for a quick tutorial on systemd daemon services:

# Starts the service
systemctl start --user spotifyd.service

# Restarts the service
systemctl restart --user spotifyd.service

# Enables the service; it should autostart on boot
systemctl enable --user spotifyd.service

# Disables the service; it should stop autostarting on boot
systemctl disable --user spotifyd.service
# again, I'm not sure this works with my configuration. It wasn't ideal.

# Checks how the service is going
systemctly status --user spotifyd.service

At this point, you should have a functional spotifyd instance running. If you check your devices on any client, you should see your device popping up, and can play audio through this.

Running a client

At the moment, I’m just using Spotify TUI, written in Rust. This step is not necessary if you want to, say, play music from your phone.

Installation instructions are given here. For arch-based systems, run yay -S spotify-tui (or use your preferred AUR helper. If you’re new to the AUR, check the arch wiki). This will take a while as it compiles.

Once done, you can launch the client by running spt on the terminal. Configuration is easy enough – the intial startup gives instructions, and they are trivial enough to follow.

The instructions offered for config

Credits

Apart from official documentation, a number of blogs and posts offered (admittedly partial) information to help sort out what exactly was to be done:

  1. No, that’s not a typo. 

tags: spotify - configuration - setup
<-- Back