-
Notifications
You must be signed in to change notification settings - Fork 217
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, as Raspotify is only intended to be used on headless systems.
These instructions will install and configure Raspotify.
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.
Make your own 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
As of Raspotify 0.43.47 the version of librespot built for Raspotify supports 44.1kHz, and though builtin resampling 48kHz, 88.2kHz and 96kHz.
librespot -d ?
Example output:
Compatible alsa device(s):
--------------------------------------------------------------------
Device:
hw:CARD=D10s,DEV=0
Description:
D10s, USB Audio
Direct hardware device without any conversions
Supported Format & Sample Rate Combinations:
Format: S32 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
--------------------------------------------------------------------
Device:
plughw:CARD=D10s,DEV=0
Description:
D10s, USB Audio
Hardware device with all software conversions
Supported Format & Sample Rate Combinations:
Format: S16 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S24 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S24_3 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S32 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: F32 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: F64 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
--------------------------------------------------------------------
Device:
sysdefault:CARD=D10s
Description:
D10s, USB Audio
Default Audio Device
Supported Format & Sample Rate Combinations:
Format: S16 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S24 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S24_3 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: S32 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: F32 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
Format: F64 Sample Rate(s): 44.1kHz, 48kHz, 88.2kHz, 96kHz
--------------------------------------------------------------------
Skip this and just use the default.
If you want to use an output other then the system default, change:
# Audio device to use, use `librespot --device ?` to list options.
# Defaults to the system's default.
#LIBRESPOT_DEVICE="default"
To:
# Audio device to use, use `librespot --device ?` to list options.
# Defaults to the system's default.
LIBRESPOT_DEVICE="your output device"
For example:
# Audio device to use, use `librespot --device ?` to list options.
# Defaults to the system's default.
LIBRESPOT_DEVICE="hw:CARD=D10s,DEV=0"
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"
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="F32"
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"
The 1st rule of resampling is; don't resample unless you have to.
Resampling is basically making an educated guess about what should be there, how educated depends on the interpolation algorithm, but none the less, it's still a guess. It will NEVER be completely accurate. It will NEVER improve the sound quality. It's a matter of how much will it degrade the sound quality.
That being said:
To set the sampling rate if your device doesn't support 44.1kHz, change:
# Sample Rate to Resample to {44.1kHz|48kHz|88.2kHz|96kHz}.
# Defaults to 44.1kHz meaning no resampling.
# The option does not exist in upstream librespot.
# DO NOT file a bug with librespot about this.
#LIBRESPOT_SAMPLE_RATE="44.1kHz"
To:
# Sample Rate to Resample to {44.1kHz|48kHz|88.2kHz|96kHz}.
# Defaults to 44.1kHz meaning no resampling.
# The option does not exist in upstream librespot.
# DO NOT file a bug with librespot about this.
LIBRESPOT_SAMPLE_RATE="match the audio output sampling rate"
For example:
# Sample Rate to Resample to {44.1kHz|48kHz|88.2kHz|96kHz}.
# Defaults to 44.1kHz meaning no resampling.
# The option does not exist in upstream librespot.
# DO NOT file a bug with librespot about this.
LIBRESPOT_SAMPLE_RATE="48kHz"
You may also want to increase the interpolation quality if you're using a sample rate other than 44.1kHz:
# Interpolation Quality to use if Resampling. {Low|Medium|High}.
# Defaults to Low.
# The option does not exist in upstream librespot.
# DO NOT file a bug with librespot about this.
LIBRESPOT_INTERPOLATION_QUALITY="High"
The best option is to just set the LIBRESPOT_FORMAT
to F32
, leave LIBRESPOT_SAMPLE_RATE
alone, and let PulseAudio handle format conversion and resampling for you.
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:
sudo apt purge -y raspotify
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