Add Aux to Sonos Using Raspberry Pi




About: I like solving problems.

I have always been fascinated by the Raspberry Pi but never had a real need for one until now. We have three Sonos components in our house: A Play 5 in the living room, a Play 3 in the bedroom and a Sonos CONNECT:AMP powering outdoor speakers on our patio. With them we can listen to practically anything except our local radio station which doesn't stream over the Internet. I have a tabletop radio upstairs in my office that has a line-out and wanted to be able to listen to it throughout the house mainly for live sports broadcasts. I could have accomplished this by buying another Play 5 or CONNECT and use their line-in but I didn't have enough room in my little office nor did I want to invest that much more money just to have that capability. I decided to learn how to program a Raspberry Pi to add a remote line-in for our Sonos speakers. I wrote this Instructable for the complete Raspberry Pi NOOB, which I was until just a few days ago, with what I feel is the most concise, least amount of steps necessary to have a Raspberry Pi automatically start serving a live 320 kbps stereo mp3 stream to Sonos within seconds of booting up. This is also the perfect way to listen to your turntable throughout the house on Sonos.

Step 1:

What you will need:

Raspberry PI 3 Model B 1.2GHz 64-bit quad-core ARMv8 CPU, 1GB RAM

A desktop or laptop computer with a microSD card reader

Monitor or TV with HDMI input (for initial setup only)

USB or bluetooth keyboard and mouse (for initial setup only)

BEHRINGER U-CONTROL UCA202 External USB Soundcard (has stereo RCA inputs)

UPDATE: If you own a turntable with USB out you may be able to just plug that into the Pi and use that as the "soundcard" and forego buying the Behringer altogether.

EDIT: I wasn't aware that Behringer has another model for the same price called the BEHRINGER U-PHONO UFO202 that has a built-in Phono preamp for turntables.

The Raspberry Pi's on-board sound card does not have audio inputs and there are very few external USB sound cards that have stereo inputs. My second choice was a stereo sound card "hat" that plugs into the Raspberry's GPIO pins but I couldn't find a case for it and I really liked the look and functionality of the Flirc Raspberry Pi case.

Flirc Raspberry Pi Case Gen2 (New Model) (aluminum case acts as a heat sink)

Mediabridge 3.5mm Male to 2-Male RCA Adapter (6 Feet) (if your analog audio source has RCA outputs then you don't need this)

Kingston 8 GB microSDHC Class 4 Flash Memory Card

Micro B USB Cable - Left-Angle

Step 2:

Navigate to on your regular computer and download It is a rather large file (~1.4 GB). Extract the contents of the zip file to your microSD card. I found it was faster writing to my SD card by first extracting the files to a temporary folder and then copying them to the card rather than extracting directly to the card.

Step 3:

Insert the microSD card with the extracted files into the SD card slot on the underside of the Raspberry Pi. Connect an HDMI cable from the Raspberry Pi to your monitor or TV. Connect the USB keyboard, mouse, ethernet cable (or you can configure Wi-Fi later), USB soundcard (the Behringer card doesn't require any additional software or drivers) and finally the Micro USB power cable.

Step 4:

The Pi will boot up to the operating system installation screen. Select only Raspbian and click Install. It will take a while to install. During my installation a little lightning bolt icon would appear intermittently at the top right of the screen. Online research revealed that if the Pi is accessing the microSD card a lot or otherwise working hard (and powering an external USB sound card in our case) and you are powering it using a USB cable plugged into a computer (not a dedicated USB power supply) you may see that icon which indicates a little undervoltage. It's perfectly normal and shouldn't affect anything. After the OS finishes installing you will get a confirmation dialog box. Click OK and the Pi will reboot.

Step 5:

After it reboots the Raspbian desktop will appear. The first thing we need to do is set a root password. Click the terminal icon on the upper left of the screen and type in "sudo passwd root" (without the quotes) and hit enter. Type in "raspberry" (without the quotes) as the password, hit enter and then type it in again and hit enter to confirm. BTW, the command "sudo" stands for "super user do" and allows you to execute commands as a super user aka root user.

sudo passwd root

Step 6:

Next we're going to enable the built-in VNC server. This makes things so much easier as you can simply copy and paste commands via VNC rather than typing them. Select GUI Menu (the little raspberry on the taskbar) > Preferences > Raspberry Pi Configuration > Interfaces. Click Enabled next to VNC and then OK. After a few seconds a VNC icon will appear on the taskbar. Click it and then the menu icon at the top right (box with 3 horizontal lines) and then Options. In the Security options set Encryption to "Prefer off" and Authentication as "VNC password". A password box will pop up. Enter "raspberry" (without the quotes) for the password into each box and click OK. You will get a second warning box that you have to click OK to confirm. We're setting up an audio streamer, not storing nuclear codes :)

Step 7:

Before we go any further we need to assign a static IP address. If your Pi's IP address is randomly assigned by your router's DHCP server, then the IP address could change later and you wouldn't be able to connect via VNC (or Sonos for that matter). RIGHT-click the network connections icon on the taskbar (the little up and down arrow icon) and select "Wireless and Wired Network Settings". LEFT-click the upper right box and select "eth0" to configure the ethernet connection or "wlan0" for wireless. I would advise assigning a static IP to only one or the other. I had a problem when I first set up my Pi where I assigned the same static IP address to both connections and my Pi's wireless locked up and I couldn't get it back working correctly so I had to start all over installing the OS. Anyway, enter the IP address you want in the IP address field and enter your router's IP address in both the Router and DNS Servers field. Click Apply and Close.

NOTE: It may be easier to assign a static IP address using your router's DHCP IP reservation feature if it has one. You may need the MAC address of the Pi or it may just show up in a list of connected devices on your router's admin page. If you need the MAC address then type in the command "ifconfig eth0" in the terminal window for ethernet or "ifconfig wlan0" for WiFi. Interestingly enough the WiFi's MAC address will show up on the line that begins with "ether"

Step 8:

Next we need to set the default screen resolution. This may seem silly seeing as how we're already connected to a monitor but later when you connect via VNC without a monitor attached (headless, as they say) it will revert back to the Pi's default 640x480 resolution which is a very tiny screen to work with! Select GUI Menu > Preferences > Raspberry Pi Configuration > Set Resolution. Set it to 1280x720 or higher and click OK and Yes to reboot.

Step 9:

At this point you may want to start using VNC to control the Pi. Open up the VNC control panel on the Raspbian desktop again and look for the IP address under "Connectivity". Install and run a VNC viewer on your regular computer and use that IP address to connect and enter "raspberry" (without the quotes) as the password. I used TightVNC for Windows. After you've connected you can save the Pi's VNC connection as a shortcut on your desktop to quickly connect in the future bypassing the logon screen. You will get a warning about saving the password within the shortcut. Again, the codes. To copy and paste into the Pi's terminal window, select or highlight the text or commands on your regular computer, hit Ctrl-C (literally hit the Ctrl and C key on your keyboard at the same time) or right-click and select "Copy", then activate the Pi's VNC viewer window and RIGHT-click inside the terminal window right on the cursor and select Paste.

Step 10:

Next we are going to test the sound card to make sure it is working properly. Plug a live audio source into the USB sound card's RCA line inputs. Open the terminal window and type in "arecord -l" (that's a lowercase "L") and hit enter. That will list your attached sound card devices. The number after the word "card" is your device number. Substitute that number in the next command after the word "plughw:" In my case my card number was "1" so I typed in (actually copied and pasted using VNC) "arecord -D plughw:1,0 -f cd temp.wav". That will start recording a CD-quality .wav file from the sound card's inputs. After a few seconds hit Ctrl-C (literally hit the Ctrl and C key on your keyboard at the same time) to stop the recording. To play it back you will need to plug headphones into the headphone jack located on the Raspberry Pi card itself or the headphone jack of the external USB sound card. RIGHT-click the speaker icon on the taskbar and select the corresponding device you just plugged your headphones into and turn up the volume (Analog = Raspberry Pi headphone jack; USB AUDIO CODEC = External USB sound card headphone jack). Type in "aplay temp.wav" and hit enter and you should hear what you just recorded. The sound card on the Pi is not very good so if you are listening via its built-in headphone jack, don't be alarmed if it doesn't sound all that great. Our audio stream will be all digital and will sound great on Sonos.

arecord -l
arecord -D plughw:1,0 -f cd temp.wav
aplay temp.wav

Step 11:

Next we are going to install two programs, Darkice and Icecast2. Darkice is what will be encoding our live audio source into an mp3 stream and Icecast2 is what will be serving it to Sonos as a Shoutcast stream. Type in each of these lines in the terminal window one at a time followed by the enter key each time:

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

Step 12:

Now to install Icecast2. Type in "sudo apt-get install icecast2" followed by enter. After it installs a window will pop up asking if you want to configure Icecast2. Hit the left arrow key and enter to select Yes. On the second screen hit the down arrow key and enter to select OK to use the default hostname "localhost". On the next three screens hit the down arrow and enter key to agree to use "hackme" as the default source, relay and administration password. Even though we are agreeing to all of the default settings, these steps must be completed to activate the Icecast2 server.

sudo apt-get install icecast2

Step 13:

Next we need to run the GUI file manager as root user. To do this, select GUI Menu > Run. Type in "sudo pcmanfm" and hit enter. That will open up the file manager (the equivalent of file explorer for us Windows users) to the home directory (/home/pi) and you will see the leftover darkice installation file we previously downloaded along with the temp.wav file we created to test the sound card. RIGHT-click on an empty space in the explorer window and select Create New and then Empty File. Name it "darkice.cfg" and click OK. Then RIGHT-click that newly created file and choose to open it with Leafpad (the equivalent of Windows notepad). Copy the lines below and paste them into Leafpad then click File and Save. The settings I have selected are for the best quality mp3 stream but you may want to tweak them to lower quality settings if you are going to be streaming outside your network e.g. the Internet. Make sure your sound card number is correct in the line "device = plughw:1,0" You'll notice the "quality" line is commented out with a # in front of it. It is used only if you set "bitrateMode = vbr" (variable bitrate). You can't have a quality value set when using cbr (constant bitrate) or the stream will stutter and skip. I only discovered this little gem after many hours of frustration. I assumed the quality value would be ignored if you were using cbr but it turns out that is not the case and really throws a monkey wrench into the works. Conversely, if you decide to use vbr then you need to comment out the "bitrate = 320" line and uncomment the "quality" line.

duration        = 0      # duration in s, 0 forever
bufferSecs      = 1      # buffer, in seconds
reconnect       = yes    # reconnect if disconnected

device          = plughw:1,0 # Soundcard device for the audio input
sampleRate      = 44100   # sample rate 11025, 22050 or 44100
bitsPerSample   = 16      # bits
channel         = 2       # 2 = stereo

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 14:

Next we need follow the same steps as before to create an empty file called "". An .sh file is the equivalent of a .bat or batch file for DOS or Windows. Open using Leafpad, copy and paste the lines below and save.

sudo /usr/bin/darkice -c /home/pi/darkice.cfg

Step 15:

Next we need to run a command to make the file executable. Open the terminal window and type in "sudo chmod 777 /home/pi/" and hit enter. Now it's time to start the Icecast2 server service. Type in "sudo service icecast2 start" and hit enter.

sudo chmod 777 /home/pi/
sudo service icecast2 start

Step 16:

Next we need to tell Darkice to start automatically whenever the Pi is booted (the Icecast2 server runs as a service and already starts automatically after booting). First we need to select which text editor to use. In the terminal window type "select-editor" and hit enter. Type "2" to select nano editor and hit enter. Then type "crontab -e" and enter. Next hold the down arrow key down to scroll all the way to the bottom of the text file that appears and add this line "@reboot sleep 10 && sudo /home/pi/". Then hit Ctrl-X to exit and it will prompt "Save modified buffer?". Hit the Y key for Yes then enter to confirm whatever filename is automatically generated. The sleep 10 switch tells the Pi to wait 10 seconds after booting before starting the audio stream. This gives the OS time to initialize the USB sound card. If you start the stream before the USB sound card is active, the stream will never start.

crontab -e
@reboot sleep 10 && sudo /home/pi/

Step 17:

Click the GUI menu icon and select reboot. If you followed all these steps precisely then the stream will start automatically anywhere from 30 seconds to a minute after clicking reboot.

Step 18:

UPDATE: I cannot get my stream to play directly in Google Chrome anymore. I think it got broken with a Chrome update. It still works fine on Sonos and my other streaming apps.

To test that the stream is working correctly, open the web browser on your regular computer and navigate to "" (with your Pi's correct IP address substituted for mine of course) to view the status of your Pi's Icecast2 server. To listen, click on the M3U icon in the upper right or you can manually enter "" to open the stream directly and skip downloading the .m3u playlist file altogether. If you hear your live source then the Pi is working correctly and it's time to add it to Sonos.

Step 19:

You must use the Sonos desktop controller app to add a custom stream to Sonos. Click on Manage > Add Radio Station and enter the url for the stream which in my case was "". Also enter a Station Name and click OK.

Step 20:

To play the custom radio station we just added, select "Radio by Tunein" and then "My Radio Stations" and then you will see your Raspberry Pi listed. LEFT DOUBLE-click to play or RIGHT-click to edit or add the station to your Sonos favorites.

Step 21:

After adding the custom radio station it will immediately be available on your Sonos mobile app. Sonos recently updated their app to a ghastly white motif as well as renaming "Sonos Favorites" to "My Sonos" and using overly large thumbnails for everything. There has been a lot of backlash on the Sonos forums as the old format looked and worked so well with everything easily accessible without blinding you in a dark room. Hopefully they will revert back to the old style soon. Anyway, on the new app, tap "My Sonos" at the bottom, scroll down to "Stations" and tap "See All". On the next screen scroll down until you see "Raspberry Pi". Tap on it and it will start playing in your selected room(s).

Step 22:

The last thing to do is to install the Pi in a case. I chose the Flirc Raspberry Pi Case because it both looks good and is functional. The entire aluminum case acts as a heat sink for the Pi's processor. If you get this case, peel off the sticky side of the spongy thermal pad that is included and stick it on the part of the case that reaches down to touch the processor and then peel off the thin plastic film on the other, non-sticky side (the side that touches the processor) before closing up the case.

Step 23:

Just a bit of house cleaning: If you plan to leave your Pi connected via ethernet then you may want to turn off its Wi-Fi radio to conserve a little juice. To do this LEFT-click the network connections icon (the little up and down arrow icon) and select "Turn Off Wi-Fi". You can also turn off the bluetooth radio by LEFT-clicking the bluetooth icon. Also, the Darkice program runs hidden in the background so if you ever need to stop it then open a terminal window, type in "ps aux | grep darkice.cfg" and hit enter and then "sudo kill 976" (or whatever the first process ID is) and hit enter. To restart the stream type in "sudo darkice -c ~/darkice.cfg" and hit enter or just simply reboot. I was curious how much bandwidth the Pi used when there were no clients attached to the Icecast server so I installed a bandwidth monitoring tool called vnstat and the answer is 0 kbps. If there are no clients connected then there is absolutely no bandwidth used whatsoever. Good luck and thanks for looking!

ps aux | grep darkice
sudo kill 976
sudo darkice -c ~/darkice.cfg

Step 24:

UPDATE: I moved out of state recently and wanted to to continue to listen to my sports team's game broadcasts on my Sonos speakers. I wrote a script 17 years ago that reads all my team's sports schedules every morning to see if there's a game being played that day. If there is it sends me an email, sets my computers Hauppauge Colossus HDMI capture card to record the game from the cable box and Total Recorder records the radio broadcast from a radio connected to my computer's line-in. Since I am going to be out of state the radio does me no good now so I set up a Raspberry Pi to automatically launch the game broadcast stream in a web browser when it is booted. So what happens now is when the pregame starts my computer automatically turns on a Wemo switch connected to the Pi and it boots and starts playing the radio broadcast and I record from the Pi's headphone out using my computer's line-in. I was having my main computer launch the webpage and recording it internally but I didn't like having my computer tied up the whole game. I also wanted to stream the audio to my Sonos speakers and thought it would be simple to do using only software but it turns out that is not the case since Darkice is looking for an audio input signal, not an output. The easiest and most reliable way is to simply plug one end of a 3.5mm to 2x RCA adapter into the Raspberry Pi's headphone out and the other end into the Behringer's RCA inputs and perform the steps in this instructable to stream the AUX input from the Behringer. FYI, to automatically start a webpage at boot you need to edit the autostart file in /etc/xdg/lxsession/LXDE-pi/autostart and add this line at the end:


It works great!

Raspberry Pi Contest 2017

Runner Up in the
Raspberry Pi Contest 2017

16 People Made This Project!


  • Weaving Challenge

    Weaving Challenge
  • Pie Contest

    Pie Contest
  • Trash to Treasure

    Trash to Treasure

65 Discussions


13 days ago

I’ve got it all working, using a CHIP Microcomputer rather than a RPi.

The only issue I am having is that the sound quality is very distorted, to the extent that it’s beyond listenable. Anyone got any ideas on what might be the issue there?

1 answer

Question 9 months ago

Thanks for the great project.
Everything works fine !!! Great Job !!!


I use it to send the TV audio out > to the sonos speakers. It works good but the delay between the TV picture and the sound is poor. The TV audio sound via Sonos is 2 seconds later than the TV picture. (not synchron) This dosent feel good.

Is it possible to reduce the delay of recording the TV audio and replay back over sonos ?



1 answer

Answer 4 weeks ago

I'm having the same problem. Did you find a solution to reduce the delay?


Question 6 weeks ago

Anyone else have an issue where streaming stopped working after several days of not using?

I went to use my turntable earlier and got nothing. Tried rebooting the Pi, still nothing. I ended up going back to the instructions and re-did 11-16. That got it working again.


Question 6 weeks ago

Hi All!
First of all - thank you very much for the instructions, great solution.

One issue that I have just noticed - it appears that the output volume levels are lower than for 'standard' radio stations / spotify. i.e. if I play the raspberry pi stream on play:1 at, let's say, 20%, the volume will be significantly lower than with any other station.
Question is - has anyone else encountered this 'problem' and can it be solved? In general, not a huge pain, however, can lead to some unexpected surprises when switching between inputs

thanks a lot

Carsten TanderJ

Question 7 weeks ago

Super easy guide to follow, although I'm brand new as Raspberry Pi user.

However, I have a problem after about 20 - 25 minutes, the music begins to chop for a few minutes, after which it completely stops, then it starts again perfectly and after about 20 - 25 minutes it begins to chop again, it continuous like this.

I use a Raspberry Pi 3 b+ and have tried it over wifi and ethernet cable but with same result ☹

Have anyone tried something similar?


7 weeks ago

Thanks for sharing this - After getting the USB sound card delivered, I set this up in about an hour. Super clear instructions for a complete novice.

Although I wish I would have checked my record player before I bought the sound card, turns out it already had USB out... Oh well!


Question 2 months ago on Step 7

Whatever this was...ultimately didn't matter. Works perfectly.

Managed to configure a static IP address but, the MAC address shown when running the terminal ifconfig command is not matching up with the device MAC address that shows up in my router "connected devices" table.


2 months ago

Wow! Amazing work around. My connect just broke and followed these steps rather than fork over the 350 for a new one. After listening for 10-15 minutes im convinced the quality is even better. Thanks for figuring this out and introducing me to the world of raspberry pi.


Question 2 months ago on Introduction

Hi replayreb,
1st of all, great job on coming up with this solution and providing such a detailed guide.
before i jump into this project, i wanted to ask if there was an update regarding the sound card. i was looking around at the behringer usb sound card you used and while browsing their products, i found the UM2 model ( which retails for the same price as yours, and while it looks nicer and neat i was wondering if it will work/any feedback ...
i looked for the Rpi "hat" soundcard but like you mentioned before, i couldnt find a good case for it with the Raspberry pi.

thanks again!


2 months ago

If i do go directly from Record player to Raspberry Pi device will I need to make any changes to the settings in step 13? I'm a total "noob" and any help would be greatly appreciated as I embark on this project.

1 reply

Reply 2 months ago

No, you won't have to make any changes. Those settings will give you the highest quality stream possible. Edit: I didn't read carefully enough; Are you plugging a USB record player into the Pi? If so and it's the only audio USB device plugged in then the soundcard number still should be "1" for the plughw:1,0 value. Type in arecord -l (that's a lowercase "L") at the terminal prompt to list your available soundcards (a USB record player is seen as a soundcard) and make sure that's the correct soundcard number. If it's listed as "2" then simply change the plughw value to plughw:2,0


8 months ago

This all looks very interesting, if I had a turntable that contained a pre-amp and usb output, I’m assuming I wouldn’t need the external usb soundcard and can just plug the usb output directly into the Pi?


Well, the answer was a resounding yes, so all good.

Has anyone worked out how to get icecast to provide an image that the Sonos controller app will show? Thanks

1 reply

Reply 2 months ago

Did you have to change any of the settings from the instructable above to make this work. Curious about step 13 specifically

Hi all, first at all sorry because my english is not so good and thanks at all.

I`m interested in this proyect, but with a little diference. I would like to capture intern sound (Kodi) with alsa loop for example. And then, install icecast2... like this tuto.

Is it possible?

Could you help me?.

Many thanks in advance.


3 replies

Reply 1 year ago

I can't test but you could try setting the device in the darkice.cfg file to default and see if it just streams the internal soundcard's output:


duration = 0 # duration in s, 0 forever

bufferSecs = 1 # buffer, in seconds

reconnect = yes # reconnect if disconnected


device = default

sampleRate = 44100 # sample rate 11025, 22050 or 44100

bitsPerSample = 16 # bits

channel = 2 # 2 = stereo


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


Reply 4 months ago

I moved recently and wanted to to continue to listen to my sports team's game broadcasts on my Sonos speakers so I too wanted to stream the audio playing on my Raspberry Pi's internal soundcard to my Sonos speakers so and thought it would be simple to do using software but it turns out that is not the case since Darkice is looking for an audio input signal. The easiest and most reliable way is to simply plug one end of a 3.5mm to 2x RCA adapter into the Raspberry Pi's headphone out and the other end into the external soundcard's RCA inputs. The sound is coming from a webpage I wanted to launch automatically when the Pi booted so edited the autostart file in /etc/xdg/lxsession/LXDE-pi/autostart and added this line at the end:
It works great!


Question 4 months ago

Hi there - I am very excited to give this a go to connect my vinyl to Sonos. I wanted to double check there isn't any lag in the sound with this setup?