0% found this document useful (0 votes)
3 views

Building a Raspberry Pi Audio Receiver CodeX

This article provides a guide on how to build a Raspberry Pi audio receiver that supports Bluetooth streaming, AirPlay, Spotify Connect, and UPnP. It discusses the advantages of upgrading old HiFi systems using a Raspberry Pi and a HiFiBerry DAC for improved sound quality. The document includes detailed steps for setup, installation, and troubleshooting of the audio receiver.

Uploaded by

mnnsa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Building a Raspberry Pi Audio Receiver CodeX

This article provides a guide on how to build a Raspberry Pi audio receiver that supports Bluetooth streaming, AirPlay, Spotify Connect, and UPnP. It discusses the advantages of upgrading old HiFi systems using a Raspberry Pi and a HiFiBerry DAC for improved sound quality. The document includes detailed steps for setup, installation, and troubleshooting of the audio receiver.

Uploaded by

mnnsa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Open in app

This member-only story is on us. Upgrade to access all of Medium.

Member-only story

Building a Raspberry Pi Audio Receiver


Remo Hoeppli · Follow
Published in CodeX
8 min read · Apr 5, 2021

Listen Share More

Photo by Teguh Baskoro on Unsplash

TL;DR
This post shows how to use a Raspberry Pi to build an audio receiver supporting Bluetooth
streaming, AirPlay, Spotify Connect and, UPnP.
I recently wrote another article on this topic, since I wanted to see if meanwhile there
might be another even better solution to building a Raspberry Pi audio receiver. My new
article covers HifiBerryOS a dedicated project for this purpose, that, in my opinion, is
much more advanced than the solution described in the article here. You can find the
article here.

Upgrading your old HiFi system


So many of us still have this old HiFi system, that did cost a fortune back in the time but
isn’t used so often anymore since we mostly stream music from Spotify, Soundcloud,
Mixcloud, YouTube, and other streaming platforms. What if I told you there is an easy way
to give your HiFi system an upgrade by reusing that Raspberry Pi which is getting dusty
somewhere between your other tech gadgets.

Surely, one could also just buy a streaming device that supports all the technologies
necessary. I already browsed for a well-suited device but didn’t buy it in the end, because
of the high price or maybe also because I didn’t really know what technology to go for.
Since the technology decision is nowadays a commitment to a certain manufacturer or
streaming provider. Pretty much as it was years back with Tapes, Vinyl, CDs, or MiniDisc
(right what the heck is MiniDisc =). Therefore, we lock ourselves into the ecosystem of a
big company. Using a Raspberry Pi for this purpose can cheaper and also more future-
proof. We can still use the Pi for something else if we don’t need it as a streaming device
anymore.

Awesome sound quality


If you aren’t convinced that the Raspberry Pi is a good fit to stream high-quality music,
you are partly right. While the hardware of the Pi is totally capable of handling the music
transcoding, its line-out connector isn’t really top-notch. I would even say you can play
music with it, but it does sound terrible. Fortunately, there is an easy solution to this
problem, using a HiFiBerry hat. HiFiBerry is a manufacturer specialized in producing
Audio extensions for the Raspberry Pi. I got myself a HiFiBerry DAC2 Pro which does
provide pretty good sound quality and made the music streams sound great on my
Pioneer HiFi system from 1978.

Upgraded Pioneer Hifi System from 1978

The technology behind


To implement a streaming device that supports Bluetooth streaming, AirPlay, Spotify
Connect, and UPnP we make use of different projects.

BlueALSA → Bluetooth Streaming


Shairport Sync → AirPlay
Raspotify → Spotify Connect
Gmrender-ressurect → UPnP Renderer
Snapclient → Snapcast multiroom audio player

Fortunately, there is a GitHub Repo by NicoKaiser called rpi-audio-receiver that combines


all the bricks needed and simplifies the installation procedure with a handy script.

The setup
In this post, I use a Raspberry Pi 4 but a Raspberry Pi 3 should be working as well. Using a
Raspberry Pi 2 we also require a Wi-Fi as well as a Bluetooth dongle to get full
functionality.

Preparing the microSD card


To set things up, we prepare a new microSD card with Raspbian in headless mode. I often
use ApplePiBaker to flash microSD cards on my Mac. Nevertheless, I did use Raspberry Pi
Imager for this manual since some steps are automatically done by ApplePiBaker and I
wanted this manual to be as complete and as compatible with Windows and Linux as
possible.

Therefore, the first step we do is to insert the microSD card and choose the Raspberry Pi
OS Lite.
Choosing the operating system
Getting a custom Raspberry Pi OS
Choosing Raspberry Pi OS Lite

For this project, we don’t use 64-bit and also no GUI, so we can go with the default Lite
image the Raspberry Pi Imager gives us.

Once the image is written on the microSD card, we also prepare the network
configuration and set configure the headless ssh service. To do so, we insert the microSD
card in our computer once again and create the files in the “/boot” directory.

WiFi-Setting
The first file is the “wpa_supplicant.conf” in which we define the Wi-Fi configuration for
our Pi and contains the following information:

1 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
2 update_config=1
3 country=CH
4
5 network={
6 ssid="mywifissid"
7 psk="mypassword"
8 }

rpi-audio-receiver-wpa_supplicant.conf hosted with ❤ by GitHub view raw

/boot/wpa_supplicant.conf

It is important to ensure that we select the correct country, since Wi-Fi settings will be
configured according to it. You can find the correct Alpha-2 code here. Furthermore,
make sure to change the SSID (WiFi-name) and PSK (WiFi-Password) according to your
Wi-Fi.

Headless SSH access


To automatically activate the SSH server right away, we also create a second file under
“/boot/ssh”. This file doesn’t need any content, but tells the pi to activate the SSH server
service.

Once we have created the two files, our Pi is ready to start. The next step for us is to figure
out the IP address of the Raspberry Pi. This can be accomplished using an IP-Scanner
such as fing which can be used on Android, iOS, or on the Desktop. We then connect to
the Pi via SSH using the default credentials “pi” (username) and “raspberry” (password).
For easier access, we can place our SSH public key into the “~/.ssh/authorized_keys” file.
Basic configuration
Once we have access to the Pi, we do some basic configuration steps, such as expanding
the filesystem, setting the locales, and updating the Pi.

To expand the file system, we use the raspi-config menu:

1 sudo raspi-config

rpi-audio-receiver-raspi-config.sh hosted with ❤ by GitHub view raw

raspi-config menu

We then choose “6 Advanced Options” …

Raspi-config: 6 Advanced Options

… and “A1 Expand Filesystem” to use the whole space on our microSD card.

Raspi-config: 6 … — A1 Expand Filesystem


Then we restart the “raspi-config” again and go to the menu “5 Localisation Options”.

Raspi-config: 5 Localisation Options

Then we choose “L1 Locale”

Raspi-config: 5 … — L1 Locale

In the list, we then uncheck “en_GB” and check “en_US” and continue.

uncheck en_GB

check en_US
Finally, we add the following export to the “~/.bashrc” file:

1 export LC_ALL=C

rpi-audio-receiver-bashrc.sh hosted with ❤ by GitHub view raw

LC_ALL export in .bashrc file

We then reboot the pi using “sudo reboot” and update all packages once it is booted again:

1 sudo apt update && sudo apt upgrade -y

rpi-audio-receiver-update.sh hosted with ❤ by GitHub view raw

Apt update & apt upgrade

Installing Raspberry Pi Audio Receiver


Once everything is prepared, we can now install the rpi-audio-receiver using the following
commands from the manual on GitHub and follow the instructions from the installation
script:
1 cd /home/pi
2 wget -q https://github.com/nicokaiser/rpi-audio-receiver/archive/main.zip
3 unzip main.zip
4 rm main.zip
5
6 cd rpi-audio-receiver-main
7 ./install.sh
8
9
10
11 #follow the instructions
12
13 # change the hostname
14 Hostname [hifi-office]: hifi-office
15
16 ...
17
18 # change the pretty hostname
19 Pretty hostname [hifi-office]: hifi-office
20
21 ...
22
23 # bluetooth support
24 Do you want to install Bluetooth Audio (BlueALSA)? [y/N] y
25
26 ...
27
28 # airplay support
29 Do you want to install Shairport Sync AirPlay Audio Receiver (shairport-sync v3.3.7)? [y/N] y
30
31 ...
32
33 # spotifi connect support
34 Do you want to install Spotify Connect (Raspotify)? [y/N] y
35
36 ...
37
38 # upnp support
39 Do you want to install UPnP renderer (gmrender-resurrect)? [y/N] y
40
41 ...
42
43 # multi room audio system
44 Do you want to install Snapcast client (snapclient})? [y/N] y
45
45
46 ...
47
48 # if we don't have a pi vu meter from pimoroni we don't need this
49 Do you want to install ALSA VU meter plugin (pivumeter) [y/N] N
50
51 ...
52
53 # do this if you have a HifiBerry
54 Do you want to enable HiFiBerry device tree overlay and ALSA configuration? [y/N] N
55
56 ...
57
58 # could be activated to protect sd card from corruption
59 Do you want to enable read-only mode? [y/N] N

rpi-audio-receiver-installation.sh hosted with ❤ by GitHub view raw

Install rpi-audio-receiver

The commands above will install everything without a HiFiBerry DAC hat. If we want to
enable the HiFiBerry separately, we can still do it afterward using the following
commands:

1 cd /home/pi/rpi-audio-receiver-main
2 sudo ./enable-hifiberry.sh
3
4 #follow the instructions
5
6 # enable HiFiBerry
7 Do you want to enable HiFiBerry device tree overlay and ALSA configuration? [y/N] y
8
9 # choose the right dt overlay configuration
10 Which board do you want to enable? [dac/dacplus/dacplusadc/dacplusadcpro/dacplusdsp/digi/digipro/amp] da

rpi-audio-receiver-hifiberry-installation.sh hosted with ❤ by GitHub view raw

The HiFiBerry manual helps to choose the right device tree overlay (dtoverlay)
configuration.
We can now restart our Pi again using “sudo reboot” and are then ready to go.

Troubleshooting the installation


ALAC problem at Shairport Sync installation
When trying to install the Shairport Sync, I came across a problem with the ALAC (Apple
Lossless Audio Codec) installation. For me, it worked to install the ALAC project from
TimothyGu.

1 sudo apt install -y git


2 cd /home/pi
3 git clone https://github.com/TimothyGu/alac.git
4
5 cd alac
6 autoreconf -i -f
7 ./configure
8 make
9 sudo make install

rpi-audio-receiver-install-alac.sh hosted with ❤ by GitHub view raw

Manually install Apple Lossless Audio Codec

Screen Reader Audio Loop


When I first installed a Raspberry Pi audio receiver, I had issues with the screen reader
audio message that was played in an endless loop. I found it easiest to apply the fix from
timg236, I found in the Raspberry Pi forum.

1 # from https://www.raspberrypi.org/forums/viewtopic.php?t=293406
2 sudo mv /usr/share/piwiz/srprompt.wav /usr/share/piwiz/srprompt.wav.bak

rpi-audio-receiver-disable-screen-reader-message.sh hosted with ❤ by GitHub view raw

rename the screen reader audio file

Raspberry Pi Audio Receiver in action


We can now connect to our Raspberry Pi as we would do it to any other Bluetooth
streaming device or Bluetooth speaker.
Connect to rpi-audio-receiver using Bluetooth

Additionally, we can pick the receiver right from the Spotify app using Spotify Connect.

Connect to rpi-audio-receiver using Spotify Connect

Moreover, using Apple's AirPlay, we can directly play music on our new Raspberry Pi
audio receiver.
Connect to rpi-audio-receiver using Airplay

Finally, we can also make use of BubbleUPnP to Stream music using UPnP.

Last Words
As we could see, converting a Raspberry Pi into a multi-technology streaming device isn’t
too complicated. Using a HiFiBerry digital-analog converter, we even get high-quality
sound. In my opinion, Plexamp could be a nice complement once an updated headless
version for the Pi is released. Please let me know what you think and if you have other
projects, that could be valuable for other readers. If you liked this blog post, make sure to
follow me and support my writing. Thanks for reading.

About the author


Remo Höppli is Co-Founder and Software Engineer at Earlybyte.

Earlybyte is an IT consultancy firm specialized in developing new digital solutions for

You might also like