Skip to content

Instantly share code, notes, and snippets.

@Kirens
Last active July 18, 2022 08:43
Show Gist options
  • Save Kirens/71e81cce7fa2a8e78f55850b44768210 to your computer and use it in GitHub Desktop.
Save Kirens/71e81cce7fa2a8e78f55850b44768210 to your computer and use it in GitHub Desktop.
raspberry-pi librespot
# Setup headless raspbian
# Install PulseAudio and vlc for http stream sinks
sudo apt install pulseaudio vlc
# Install librespot via raspotify, but disable raspotify
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
sudo systemctl disable raspotify.service
# Install librespot user service
mkdir -p .config/systemd/user .bin
mv librespot.service .config/systemd/user
mv librespot-runner .bin/
#! /bin/bash
# Ensure connectivity
if ! ping -n -c 1 -w 5 1.1.1.1 >/dev/null 2>&1
then
echo No internet detected >&2
exit 1
fi
bitrate=320
librespot \
--backend pulseaudio \
--disable-audio-cache \
--name MediaPlayer \
--device-type speaker \
--bitrate "$bitrate" \
--enable-volume-normalisation \
&
sinkName=`
pacmd list-sinks | \
grep -e 'index:' -e 'name:' | \
grep -A 1 '*' | \
grep -oP '(?<=<)[^>]+'
`
IP=`ifconfig | grep -oP 'inet 192\S+' | cut -d' ' -f2`
cvlc -q pulse://$sinkName.monitor \
--sout "#transcode{acodec=mp3,ab=$bitrate,channels=2}:standard{access=http,dst=$IP:8080/stream.mp3}"
[Unit]
Description=Librespot with cvlc http stream
Wants=sound.target
After=sound.target
[Service]
ExecStart=$HOME/.bin/librespot-runner
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment