Mastodon

Saturday 1 January 2022

Raspberry Pi Music Streaming

I want to be able to play music from my PC, phone tablet to my hifi system which is on the other side of the room. Bluetooth seems to drop out and I mostly use Spotify or Itunes as a music player. 

I thought I'd have a look at what could be done with a Raspberry Pi and an external sound card to improve the standard sound quality. In the end I tested this out with a Raspberry Pi zero W which worked quite well and ended up running it on a Raspberry Pi Zero 2.

For Spotify to work you do need Spotify premium but iTunes will work quite happily with local files.

I'm not going through with how to install Raspbian onto an SD card and configure the wifi settings here.

Here's the sound card I got hold of from Amazon. £6.99 and it seems to work quite well. You'll also need an adaptor to connect this to the micro USB socket if you're using a Pi Zero.

Once that's all connected it together and you have Raspbian Lite installed on an SD card it's time to get it up and running


As always let's update the os first.

sudo apt-get update 

sudo apt-get upgrade

Then we use the following line to install raspotify

curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

Once it's completed we can edit some settings with:

sudo nano /etc/raspotify/conf

Look for the following line.

# Device name.

# Raspotify defaults to "raspotify (*hostname)".

# Librespot defaults to "Librespot".

# LIBRESPOT_NAME="Music1"

Uncomment the last line and change the Music1 to whatever you want to call it.

Now we activate the USB sound card

sudo nano /usr/share/alsa/alsa.conf

defaults.ctl.card 0

defaults.pcm.card 0

Change the above to the settings shown below

defaults.ctl.card 1

defaults.pcm.card 1

Save the file and then run sudo alsamixer

This should show the display below, just turn the sound all the way up.


If you now run sudo service raspotify restart you should see the device name showing up in your Spotify client, if you connect the audio output to your hifi you can play music from your devices to it.

Now we're going to add Airplay support for Itunes.

sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman

git clone https://github.com/mikebrady/shairport-sync.git

cd shairport-sync

autoreconf -i -f

./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

make

sudo make install

This may take some time.

Once it's completed we just need to make sure the service runs on restart.

sudo systemctl enable shairport-sync

Give it a reboot and it should all be running nice and happy.

You should be able to see the device in Spotify and Itunes as shown below.



Thanks to the Raspotify people and Jeff Thompson for my inspiration



No comments:

Post a Comment