Sonos makes incredible smart speakers that forgo the need to use a dedicated receiver – not to mention the wiring required by conventional 5.1 surround systems. But connecting to devices like record players usually need a separate Sonos device like the Amp or Port that can cost hundreds of dollars.
The method listed here lets you skip this extra hardware, allowing you to easily connect your record player to Sonos speakers with little more than a Raspberry Pi and some open source software.
What You’ll Need
A Compatible Turntable – While any player will do, if you have a recent record player that contains USB out you will likely be able to connect your record player directly to the Raspberry Pi. If yours doesn’t support USB, you’ll need to use an external USB stereo sound card to connect the audio signal from your record player to a digital signal your Raspberry Pi can use.
I’m currently using the Audio Technica LP120XUSB-BK turntable that works incredibly well connecting directly with my Raspberry Pi. If you already have a turntable that doesn’t have a USB port, guides like this comprehensive guide from Instructables makes a few sound card recommendations to convert your record player’s analog audio into a hi-fidelity digital signal that your Raspberry Pi will be able to use.
A Raspberry Pi 3 or newer – I’m using a slightly older Raspberry Pi 3, but this should work just as well on newer Raspberry Pi 4 models too. Just make sure you’re running an updated version of Raspberry Pi OS with SSH and VNC support installed and ready to go.
A Mac or Windows PC – The final step of this guide will include saving a custom radio station to the Sonos app. Annoyingly, this can only be done using a desktop version of Sonos, and cannot be done on mobile. If you’re also setting up a Raspberry Pi from scratch, you’ll need a Mac to get the Raspberry Pi OS software up and running too.
Getting Set Up
Step 1: Preparing Your Pi
I have my Raspberry Pi running headless behind my Audio Technica turntable with just two connectors – power and the USB cord from my record player. I’ve enabled SSH to easily run remote terminal commands as well as VNC support to access the GUI desktop remotely across my network. You can follow my guides to get both of these services up and running here.
Once you have SSH and VNC running, connect your turntable to your Pi via the USB cable and power up both the Pi and record player.
Step 2: Finding Your Turntable’s Hardware Device
Before installing anything, you need to know how your Pi identifies your turntable so you can properly set that as your capture source in the steps below. You can do this by opening terminal in SSH by opening a new SSH terminal session and typing the following and pressing enter:
You should see your USB turntable as the only connected device. Note the card number in the second output row. From this example, card 2 is my turntable. Note your number and move on to the next step.
Step 3: Installing Darkice and Icecast 2
Next, you’ll install two applications. Darkice will be encoding the audio from your record player and Icecast 2 will be broadcasting this feed for your Sonos system to receive. Type in each of these commands one by one into your terminal session, followed by the enter key once the proceeding step finishes:
wget https://github.com/x20mar/darkice-with-mp3-for-raspberry-pi/blob/master/darkice_1.0.1-999~mp3+1_armhf.deb?raw=true mv darkice_1.0.1-999~mp3+1_armhf.deb?raw=true darkice_1.0.1-999~mp3+1_armhf.deb sudo apt-get install libmp3lame0 libtwolame0 sudo dpkg -i darkice_1.0.1-999~mp3+1_armhf.deb
With Darkice successfully installed, you‘ll next need to install Icecast 2. You can do so with the following terminal command:
sudo apt-get install icecast2
Once the installer finishes, you’ll see a GUI setup guide. Accept the default settings of “localhost” and “hackme” as the default password. Once the wizard closes, we’ll just need to set a few configuration settings for the streaming to work correctly.
Step 4: Setting Streaming Quality
Following the direction of replayreb from Instructables, we’ll create the config file for the streaming defaults for icecast 2.
VNC into your Pi and select Run from the main Rasbian menu. Type sudo pcmanfm and hit enter to access the File Manager as root user.
Your home folder should open. Right click in an empty space and select New File… and name it darkice.cfg.
Right-click this new file and open it with your preferred editor. I have Geany installed so I’ll use that, but any editor will work fine. Copy the below code and paste it into the blank file. These settings are directly from the Instructable guide and work perfect for my setup.
! Note under the [input] section, you’ll need to change the device number from 2 to whichever number you identified earlier in this guide.
Close the editor saving your changes.
[general] duration = 0 # duration in s, 0 forever bufferSecs = 1 # buffer, in seconds reconnect = yes # reconnect if disconnected [input] device = plughw:2,0 # Soundcard device for the audio input sampleRate = 44100 # sample rate 11025, 22050 or 44100 bitsPerSample = 16 # bits channel = 2 # 2 = stereo [icecast2-0] bitrateMode = cbr # constant bit rate ('cbr' constant, 'abr' average) #quality = 1.0 # 1.0 is best quality (use only with vbr) format = mp3 # format. Choose 'vorbis' for OGG Vorbis bitrate = 320 # bitrate server = localhost # or IP port = 8000 # port for IceCast2 access password = hackme # source password for the IceCast2 server mountPoint = rapi.mp3 # mount point on the IceCast2 server .mp3 or .ogg name = Raspberry Pi
Step 5: Making a Batch File to Start Streaming
The next thing we’ll need is a batch file to start the streaming service. Similar to the configuration file above, right click and choose New File, naming this darkice.sh and open it in your text editor. Paste in the following two lines and save the file:
#!/bin/bash sudo /usr/bin/darkice -c /home/pi/darkice.cfg
With this batch file created, we’ll need to make it executable by the Pi. In a terminal window, type the following commands followed by enter:
sudo chmod 777 /home/pi/darkice.sh sudo service icecast2 start
Step 6: Starting the Stream Automatically
The final configuration step will tell your Pi to start the Darkice service automatically when the Pi restarts. To do this, we’ll use Cron which is what Unix uses to run scheduled tasks. Go back to your terminal window and type the following and hit enter:
You’ll be presented with a few options, we’ll choose the nano editor, so let’s select 1 by typing 1 followed by the enter key.
Next, let’s edit the Cron file by running the following terminal command, followed by enter:
This will open up a text file within the terminal. Scroll all the way down to the bottom of the file and type in the following on a new line:
@reboot sleep 10 && sudo /home/pi/darkice.sh
Type Control-X to close the window, and Y to save changes to the cron file. This will add a scheduled job to begin the Darkice service 10 seconds after starting, allowing the Pi plenty of time to start up the USB turntable audio card.
Step 7: Verifying Everything Works
Reboot your Pi and start playing a record on your turntable. From your Mac or Widows computer, visit your Pi’s IP address followed by :8000/rapi.mp3 to listen to your stream. In my case, the stream address is:
Your Pi’s IP address will vary depending on your network settings. For details on how to set your router to reserve a static IP address for your Pi, click here.
If everything worked correctly, you should hear crisp audio from your computer speakers!
Step 8: Saving the Stream as a Sonos Station
Install the Sonos app on the computer you’re using to test the stream. Unfortunately, Sonos only lets you create custom radio stations using the desktop app, but hopefully this changes in the future.
With the Sonos desktop app installed, click Manage >>> Add Radio Station and enter your streaming URL. Mine was:
Pick a name for your station. I chose Turntable but anything will work here.
After a few minutes, you should be able to see this new custom station appear in your Sonos mobile app under Music >>> TuneIn >>> My Radio Stations…
Like other Sonos sources, you’ll be able to stream your turntable audio to any (or every) room of your home.
Observations & Considerations:
- While my Rasbperry Pi and record player take up very little power, when not in use, I keep them both on the same smartplug outlet so I can say “Hey Google, turn on the record player” to power up the devices, and “Hey Google, turn off the record player” to turn them off. The Pi takes about 30 seconds to power up, which is much faster than I’m able to select and begin playing a record.
- Unfortunately, I haven’t been able to fully automate powering up the turntable + Pi setup AND switching the Sonos input to the correct TuneIn radio station, but here’s to hoping for better Google Home or Siri integration in the future.
- I’ve found the darkice and icecast 2 services take very little system resources and use virtually no bandwidth when there are no active connections to the Sonos stream.
- I’m using a Google Wifi mesh network, running my Raspberry Pi headless and over a wifi connection. While I’m sure a direct ethernet connection will be faster and more stable, I haven’t noticed any degradation in audio stream quality.
- Thanks again to replayreb for the original guide that inspired this project!