-
-
Notifications
You must be signed in to change notification settings - Fork 220
Basic Setup Guide
Raspotify is built on and for Debian Stable and requires Debian Stable or a Debian Stable based/compatible OS.
armhf, arm64 and amd64 builds are provided. Support for ARMv6 (Pi v1 and Pi Zero v1.x) has been dropped.
This is a very basic guide that assumes you're starting from a fresh Debian Stable Minimal Server or Raspberry Pi OS Lite (Stable) install.
These instructions will install and configure Raspotify and will reconfigure system wide audio settings.
It will NOT explain how to install Debian, use a text editor, set up Raspotify/librespot
as a whatever-cast source or make you a sandwich.
If following these instructions breaks your system you get to keep all the pieces.
sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
This requires your output device to be "dmix-able", as in it is software mixable via ALSA's dmix plugin. The HDMI ports on Raspberry Pi's are NOT "dmix-able".
sudo apt update && sudo apt install -y --no-install-recommends libasound2-plugins
Install asound-conf-wizard
If you have added the Raspotify repo:
sudo apt update && sudo apt install -y asound-conf-wizard
If not the latest asound-conf-wizard builds can be found here:
- asound-conf-wizard-latest_armhf.deb
- asound-conf-wizard-latest_arm64.deb
- asound-conf-wizard-latest_amd64.deb
sudo awiz
Follow the prompts, take note of the Format that was used, and skip ahead to Configure librespot
.
A Glossary of Terms is available in the asound-conf-wizard
wiki if you get stuck or have questions on what settings you should pick.
aplay -l
Example output:
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 9: HDMI 3 [HDMI 3]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: D10s [D10s], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
aplay -Dhw:"your DACs actual card #" --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav
For example:
aplay -Dhw:1 --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav
Example output:
HW Params of device "hw:1":
--------------------
ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT: S32_LE SPECIAL DSD_U32_BE
SUBFORMAT: STD
SAMPLE_BITS: 32
FRAME_BITS: 64
CHANNELS: 2
RATE: [44100 384000]
PERIOD_TIME: [125 1486078)
PERIOD_SIZE: [8 65536]
PERIOD_BYTES: [64 524288]
PERIODS: [2 1024]
BUFFER_TIME: (41 2972155)
BUFFER_SIZE: [16 131072]
BUFFER_BYTES: [128 1048576]
TICK_TIME: ALL
--------------------
It may or may not already exist.
If it does exist it means that either you or some random package or script has created it at some point in the past, as it does not exist by default on a clean Debian install.
Choose the highest supported FORMAT
and desired sampling rate.
Avoid resampling by choosing 44100
, if 44100
is in the RATE
range, otherwise use 48000
or the lowest integer multiple of either.
Add:
defaults.ctl.card "your DACs actual card #"
defaults.pcm.card "your DACs actual card #"
defaults.pcm.dmix.rate "the actual rate that you want"
defaults.pcm.dmix.format "the actual format you want"
For example:
defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.dmix.rate 44100
defaults.pcm.dmix.format S32_LE
Skip this if you don't need to resample.
sudo apt install -y --no-install-recommends libasound2-plugins
echo "$(ls /usr/lib/*/alsa-lib | grep "libasound_module_rate_")" | sed -e "s/^libasound_module_rate_//" -e "s/.so$//"
Edit /etc/asound.conf
Add:
defaults.pcm.rate_converter "the actual converter you want"
For example:
defaults.pcm.rate_converter speexrate_medium
speexrate_medium
is a good default. Lower spec devices and SBC's may struggle with speexrate_best
.
This will play a noise test tone to verify everything is configured correctly.
Turn your volume down to a reasonable level 1st!!!
speaker-test -c2 -l1
librespot
doesn't care about the endianness (the LE
or BE
at the end) it will take care of that for us.
To set the format change:
# Output format {F64|F32|S32|S24|S24_3|S16}. Defaults to S16.
#LIBRESPOT_FORMAT="S16"
To:
# Output format {F64|F32|S32|S24|S24_3|S16}. Defaults to S16.
LIBRESPOT_FORMAT="match the audio output format"
For example:
# Output format {F64|F32|S32|S24|S24_3|S16}. Defaults to S16.
LIBRESPOT_FORMAT="S32"
If you're not limited by data caps or connection speeds you may also want set the audio quality to 320kbps by changing:
# Bitrate (kbps) {96|160|320}. Defaults to 160.
#LIBRESPOT_BITRATE="160"
To:
# Bitrate (kbps) {96|160|320}. Defaults to 160.
LIBRESPOT_BITRATE="320"
Unless you have disabled zeroconf (mDNS) discovery, librespot
does not need your Spotify credentials, zeroconf will take care of authentication.
However if you have disabled discovery for whatever reason and you provided your credentials you will also want to enable credential caching so that librespot
will cache the auth token and not have to login every time you connect. Unless you like nag emails ofc?
To enable credential caching change this in /etc/raspotify/conf
:
# Disable caching of credentials.
# Caching of credentials is not necessary so long as
# LIBRESPOT_DISABLE_DISCOVERY is not set.
LIBRESPOT_DISABLE_CREDENTIAL_CACHE=
To this:
# Disable caching of credentials.
# Caching of credentials is not necessary so long as
# LIBRESPOT_DISABLE_DISCOVERY is not set.
# LIBRESPOT_DISABLE_CREDENTIAL_CACHE=
By default librespot
"download buffers" tracks, meaning that it downloads the tracks to disk and plays them from the disk and then deletes them when the track is over. This practice is very common, many other audio frameworks and players do the exact same thing as a disk based tmp cache is easy to use and very resilient. That being said there may be cases where a user may want to minimize disk read/writes.
If you don't know what this means or understand the ramifications do NOT do this.
To make Raspotify use tmpfs for /tmp
change this in /etc/raspotify/conf
:
# Commenting this out will cause `librespot` to use a tmpfs so that provided there
# is enough RAM to hold the track nothing is written to disk but instead to a tmpfs.
# See https://github.com/dtcooper/raspotify/discussions/567
# And https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html
TMPDIR=/tmp
To this:
# Commenting this out will cause librespot to use a tmpfs so that provided there
# is enough RAM to hold the track nothing is written to disk but instead to a tmpfs.
# See https://github.com/dtcooper/raspotify/discussions/567
# And https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html
#TMPDIR=/tmp
If you run UFW on your pi, you'll find that you need to open some ports for it to work. First, specify the zeroconf port in /etc/raspotify/conf
:
LIBRESPOT_ZEROCONF_PORT="65444"
Next, allow ports 5353 UDP and 65444 TCP. On a network running on the 192.168.11.0/24
space that looks like this
sudo ufw allow from 192.168.11.0/24 to any port 5353 proto udp
sudo ufw allow from 192.168.11.0/24 to any port 65444 proto tcp
If you're setting up UFW for the first time, make sure you also allow port 22 for ssh. If you already use UFW you will have this.
sudo ufw allow from 192.168.11.0/24 to any port 22 proto tcp
This is what your UFW config might look like if these are the only ports you've opened:
pi@raspberrypi:~ $ sudo ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW 192.168.11.0/24
5353/udp ALLOW 192.168.11.0/24
65444/tcp ALLOW 192.168.11.0/24
To make sure all changes take effect you must restart the Raspotify service:
sudo systemctl restart raspotify
Completely uninstall Raspotify and asound-conf-wizard:
sudo apt purge -y raspotify asound-conf-wizard
Remove the repo:
sudo rm -f /etc/apt/sources.list.d/raspotify.list
Delete the repo's key:
sudo rm -f /usr/share/keyrings/raspotify_key.asc
Delete /etc/asound.conf
:
sudo rm -f /etc/asound.conf