5817476348

I recently found myself facing a problem: After stuffing two 28″ monitors and a high-end PC on my desk, there’s no room left for a set of speakers! I love my music, so living without a way to listen out loud just wasn’t going to happen. I already have a set of pretty decent Wharfedale Diamond 9 speakers, so I set about trying to build a solution that would please both my ears and my wallet. A full list of parts and prices are at the bottom of this post. 

There are a few things I want to achieve with this project:

  • To make the system as discreet as possible.
  • To be able to stream audio from multiple services.
  • To make the system sound as good as possible.
  • To spend as little as possible!

Part 1: The hardware

The Raspberry Pi 3 and the the Raspiaudio sound card hat are the heart of this build. At only £13, this sound card hat was an insta-buy and I’m really happy with it! It’s designed for the raspberry pi zero, but works with the larger boards just fine (I already had the Pi 3, so that’s what I’m using.)

The hat support 3.5mm and RCA outputs.
Some soldering is required to attach the RCA jacks and I/O header block.

With the RCA output attached, and the IO header block soldered on, we can mount the board to the top of the Pi. 

The hat mounted on top of the Pi.
I mangled the Raspberry Pi case to allow access to the RCA outputs.

To amplify the output of the sound card, I’m using a cheap £25 amp from Amazon. I have a few of these around my house and they’re great quality for the price. The amp is fed using the RCA outputs, but it also supports a 3.5mm jack input if that’s more your cup of tea. 


Power is run from behind, through a hold drilled in the back of the bookcase. There’s normally books between the two speakers.

I wanted this project to be as unobtrusive as possible, so I decided to install it in one of the IKEA bookcases in my study (A fitting home for a set of bookshelf speakers, when you think about it). Both the Pi and amp are tucked behind the right-hand-side speaker. A lump of blu-tack is used to keep the Pi stable on top of the amp.

While the amp has treble/bass and volume controls, I’ve chosen to ignore these as they’re can’t easily be changed. The treble/bass is bypassed using a switch on the front, and the volume dial has been set to about 75% – I find this is about as loud as I’d ever need, and the volume can be adjusted down in software (more on that later)


Remember: Nobody can judge your shitty cabling job if they can’t see it!

With the hardware installed, let’s move on to the software!

Part 2: Software.

To set the Pi up, first download the Raspbian Lite Image – we don’t need the full image, as we don’t need a desktop interface. Then burn the image to the SD card. My preferred utility to do this is etcher.io, which works across Windows, Linux, and MacOS. A more detailed guide can be found here.

We’re going to need to do a few things before we can boot up our Pi. The first is to enable SSH right from the get-go. This can be done by creating an empty file called ‘ssh’ on the root of the SD card. Make sure there’s no file extension

The second is to pre-load Wi-Fi credentials – this can be done by creating a file called ‘wpa_supplicant.conf’ on the root of the SD card and entering the below, swapping out the values in the quotation marks to match your network.

EDIT: User ‘ pfletch101‘ on the Raspberry Pi forums pointed out that the 2-letter country code is necessary for the Pi3B+. It’s not needed on older models, but it doesn’t do any harm adding it. 

network={
    ssid="your_wifi_network"
    psk="your_wifi_network_password"
    key_mgmt=WPA-PSK
    country={2-letter country code}
}

With this done, we can power up the Pi and SSH straight in to start setting things up. The first thing you’re going to want to do is grab the driver for the Raspiaudio sound card hat – this can be done by running the following command to download and run the driver install script:

sudo wget -O - script.raspiaudio.com | bash

Let the script run, and reboot when prompted. You can then test the amp using the following command:

sudo speaker-test -l5 -c2 -t wav

Now that we have the sound card driver installed, we can start thinking about how we’re going to push audio to this thing! I use both Spotify and Plex, so being able to play audio from these applications was essential. I’m also an iPhone user, so support for AirPlay would be a bonus as well. Thankfully, all three of these can be achieved!

Spotify:

To make the Pi show up as a Spotify Connect device, we can use the software package 9056870768.  To install, run the following command to download the installer and run it:

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

This script automatically adds the Raspotify repo to your system, and installs the Raspotify package. Manual install instructions are available on the project’s (304) 771-9087page.

This is the minimum you can do to get Raspotify up and running, but there are a few tweaks I have made to the /etc/default/raspotify file – changing the name that shows up in the Spotify client, and telling the software to stream at the max audio quality. Make sure to un-comment the ‘DEVICE_NAME’ and ‘BITRATE’ lines.

# Device name on Spotify Connect
DEVICE_NAME="Study Receiver"

# Bitrate, one of 96 (low quality), 160 (default quality), or 320 (high quality)
BITRATE="320"

With this done, re-start the Raspotify service with the below command:

sudo service raspotify restart

Our Pi now shows up as a Spotify Connect device!

Plex:

To cast Plex audio to our Pi, we’re going to use the Plexamp software, running in headless mode. This is a bit of a hack but works just fine once it’s set up. These instructions have been expanded from a post on the 7606337572

The first step is to download and install the Plexamp client on something else, as we need to extract the server.json configuration file that lets our Pi talk to our Plex account. Plexamp is a GUI application and since our Pi is headless, we can’t do this on the Pi itself. 

Once you’ve installed Plexamp, log in using your Plex account, and set the name you want for your receiver. Next you’ll need to find the server.json file – In windows, it’s located here: 

C:\Users\%username%\AppData\Local\Plexamp\Plexamp

Copy the file over to the Pi, and then log out of Plexamp (the config file can’t be used in two places!).

We’re going to need to install node.js onto the Pi, so add the repo and install:

curl -sL /deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt install -y nodejs

Next, download Plexamp to /home/pi:

cd /home/pi
wget /files.plexapp.com/elan/plexamp-v1.0.5-pi.tar.gz

unpack the archive, and cd into the plexamp directory

tar -xzf plexamp-v1.0.5-pi.tar.gz
cd plexamp

There’s a file here called ‘plexamp.service’. We’ll need to move this to the Pi’s systemd directory so we can run Plexamp as a service:

cp plexamp.service /lib/systemd/plexamp.service

Remember the server.json file from earlier? now’s the time to move it to the /home/pi/.config/Plexamp/ directory.  With this done, we can enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable plexamp.service
sudo service plexamp start

And with that, our Pi shows up as a device we can cast Plex to! 

AirPlay:

AirPlay functionality will be provided by the firing charge software, which is present in the Debian repos, and so can be installed with Apt:

sudo apt install shairport-sync

The only configuration change we need to make is to change the name that will show up in the list of AirPlay devices – this can be done by editing /etc/shairport-sync.conf, and changing the ‘name’ line.

name = "Study Receiver"

Save the file, and bounce the service. 

sudo service shairport-sync restart

We can now cast audio to our Pi from iDevices!

Conclusion:

I’m extremely happy with how this project turned out! Since I already had almost everything I needed, This only cost me the £13 for the Raspiaudio sound card hat, however I’ve done a rough costing below of everything you’d need to buy from Amazon, but you can probably shop around and get things a bit cheaper.

I’ve left a specific speakers out of the parts list because you can really use whatever your budget allows! The speakers I used were ~£60 when I bought them, but you can really get whatever you want. I’d recommend looking in your local charity/second hand shops and trying to get a bargain on an old pair of bookshelf speakers.

What would I do differently?

  • Run an Ethernet cable: This is specific to my situation, but the Wi-Fi reception in my study is pretty lackluster and I have had a few instances of the signal dropping out.
  • Use a Raspberry Pi Zero: I already had the Pi 3, so that’s what I used, however  a Pi Zero would have worked fine and reduced the overall footprint.