Skip to content

Play via Bluetooth Speaker

Jason Gray edited this page Aug 4, 2022 · 3 revisions

FIXME

These instructions are old and may not work as intended.

When running Raspotify with Raspberry Pi Desktop, Raspotify needs to be installed as a user service, rather than a system service. This causes Raspotify to be in the same process as the PulseAudio service, where the PulseAudio service is what is providing sound to your output device.

To configure Raspotify as a user service for your pi user, open a terminal and:

  1. mkdir -p ~/.config/systemd/user
  2. cd ~/.config/systemd/user
  3. create a file named raspotify.service containing:
[Unit]
Description=Raspotify
Wants=pulseaudio.service

[Service]
Restart=always
RestartSec=10
Environment="DEVICE_NAME=raspotify (%H)"
Environment="BITRATE=160"
Environment="CACHE_ARGS=--disable-audio-cache"
Environment="VOLUME_ARGS=--enable-volume-normalisation --volume-ctrl linear --initial-volume 100"
Environment="BACKEND_ARGS=--backend alsa"
Environment="DEVICE_TYPE=speaker"
EnvironmentFile=-/etc/default/raspotify
ExecStart=/usr/bin/librespot --name ${DEVICE_NAME} --device-type ${DEVICE_TYPE} $BACKEND_ARGS --bitrate ${BITRATE} $CACHE_ARGS $VOLUME_ARGS $OPTIONS

[Install]
WantedBy=default.target

The main difference betweeen this file and the file Raspotify lands in /usr/lib/systemd/system/raspotify.service is that the following lines are removed:

After=network.target

User=raspotify
Group=raspotify
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -m 0755 -p /var/cache/raspotify ; /bin/chown raspotify:raspotify /var/cache/raspotify

WantedBy=multi-user.target

And the following lines have been added:

Wants=pulseaudio.service

WantedBy=default.target

Once this file is created, run sudo systemctl disable --now raspotify.service to disable the system service and systemctl --user enable --now raspotify.service to register and start the user service.

At this point, Raspotify should play via whatever audio device is configured using the PulseAudio Volume Control on Raspberry Pi Desktop Panel.

Play via Bluetooth Speaker without Raspberry Pi Desktop

via asound.conf

You need to have bluealsa installed for this. It is not available in the Bullseye repositories, so you need to build it from source yourself or need to get it from somewhere else.

  1. Edit /etc/asound.conf: `> vim /etc/asound.conf

  2. Add your bluetooth MAC adresss instead of XX:XX:XX:XX:XX:

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "XX:XX:XX:XX:XX"
defaults.bluealsa.profile "a2dp"

pcm.btheadset {
    type plug
    slave {
        pcm {
              type bluealsa
              device XX:XX:XX:XX:XX:XX
              profile "auto"
         }   
    }   
    hint {
         show on
         description "BT Headset"
    }   
}
ctl.btheadset {
    type bluetooth
}
  1. Restart service:

> sudo service raspotify restart

via pi-btaudio

Another way to resolve any issues to install pi-btaudio alongside with raspotify: https://github.com/bablokb/pi-btaudio (remove pulseaudio if you have it).

If you are using Bullseye you absolutely must have installed the packages bluealsa python-dbus python-gobject beforehand. The pi-btaudio install script doesn't handle the case that some of these packages are not in the official repositories anymore and will break your bluetooth configuration.

Uninstalling

To uninstall, remove the package,

sudo apt-get remove -y raspotify

To completely remove Raspotify and its Debian repository from your system try,

sudo apt-get remove -y --purge raspotify
sudo rm -v /etc/apt/sources.list.d/raspotify.list