[Maurice-Michel Didelot] owns a Sonos smart speaker, and was lamenting the devices inability (or plain unwillingness) to stream music from online sources without using a subscription service. YouTube Music will work, but being a subscription product there is a monthly fee, which sucks since you can listen to plenty of content on YouTube for free. [Maurice] decided that the way forward was to dig into how the Sonos firmware accesses ‘web radio’ sources, and see if that could be leveraged to stream audio from YouTube via some kind of on-the-fly stream conversion process.
So let’s dig in to how [Maurice] chose to approach this. The smart speaker can be configured to add various streaming audio sources, and allows you add custom sources for those. The Sonos firmware supports a variety of audio codecs, besides MP3, but YouTube uses the MP4 format. Sonos won’t handle that from a web radio source, so what was there to do, but make a custom converter?
After a little digging, it was determined that Sonos supports AAC encoding (which is how MP4 encodes audio) but needs it wrapped in an ADTS (Audio Data Transport Stream) container. By building a reverse web-proxy application, in python using Flask, it was straightforward enough to grab the YouTube video ID from the web radio request, forward a request to YouTube using a modified version of pytube tweaked to not download the video, but stream it. Pytube enabled [Maurice] to extract the AAC audio ‘atoms’ from the MP4 container, and then wrap them up with ADTS and forward them onto the Sonos device, which happily thinks it’s just a plain old MP3 radio stream, even if it isn’t.
Sonos doesn’t have the best reputation, let’s say, but you can’t deny that there’s some pretty slick tech going on inside. Here’s a neat hack we covered last year, adding Sonos support to an old school speaker, and a nice teardown of a IKEA Sonos-compatible unit, which uses some neat design hacks.
Thanks [mip] for the tip!
Featured image by Charles Deluvio on Unsplash.
Yet another reasons to not buy Sonos crap: “the devices inability (or plain unwillingness) to stream music from online sources without using a subscription service.”
This is clearly piracy. For shame! YouTube won’t be able to survive if people keep on blocking it’s ads and stealing it’s music!
Hahahahahahaha, stop it, stop it, I’m gonna pee!
The ‘straightforward enough’ in that 3rd paragraph is doing a LOT of heavy lifting :)
Lot of old, unsupported internet radios out there that sound just fine but can’t connect to sh!t, here’s a solution.
Wow ! My article ! Thanks :)
Yes it is, and I think it’s a great article. thanks for sharing the details. I’ve no experience how to do this from scratch and since I have Sonos 5’s i’ll be trying to emulate your results. I was so impressed when I got the speakers and replaced my medicore system and enjoyed the interface with its limitations until they changed it and my ux went to sh#t bcos basic things like creating groups kept failing or failure to play iradio as my alarm.
Get a raspberry pi and install Logitech Media Server (LMS), this will control the alarms and play the play the music from any source. You can use an app such as Squeezer on your phone to manage the lot. It also allows you to sync multiple speakers. There are several guides online on how to pair a Sonos speaker to LMS.
have they found a way to unbrick them yet.
Yeah this is cool. But would be way better if it grabbed the audio stream from the PC. Then it would play anything you could want(probably with some lag).
Currently I have a Sonos sound bar at my desk which accepts optical inputs. Then a converter to convert analog to optical. Works great and no noticeable latency
I play my PC audio all the time to Sonos though the line in on a Five. No audio at at all.
You can ditch the Five and just use the TuneBlade app on your PC to stream audio over the network. Best $10 I ever spent. If you set the buffer to zero milliseconds, it’s pretty lag free. I watch video on my PC and the audio syncs well when streaming to my Sonos.
Bubble upnp app streaming from an Android device works like charm on a Bose device, Which i think are even less friendly than sonos
I’ve found Logitech Media Server (LMS) running on a raspberry pi a pretty useful tool in this regard. There’s a YouTube plugin amongst others. The upnp/dlna bridge plugin takes care of the Sonos side of things and most other devices too. The material skin plugin gives it a nice modern look too.
I got into LMS just a month ago, and I am just amazed how easy it is, and how much it can do.
There’s a vastly easier way of doing this, if you have a Sonos soundbar. Play YouTube on your TV and group your other speakers with the Beam/Arc/etc.
Yep, SONOS Bar is the only product allowing you to do this, as it has audio input. But most people only have a Beam, which only has a internet port. That was my case, and that’s the why of this project.
The beam works very well doing this. No need for extra audio input. Also a great app for YouTube on Sonos without a TV is the Sonotube on the official app-/playstore. Trial and then one payment of somewhere around $5-10 and you good to go
Can Anyone here please break this down for the dummies like me who have ZERO idea how to actually DO this! No PC here just android phone and ipad and a sonos Play 1. Make it clear and you might help someone less blessed with um “tech-telligence” cheers… Much obliged
Hey ! Article author here. I will soon release an Android / iOS app for it. You will be able to use it for free once it is validated by google and apple.
One can also use Streamlink with streamlinksrv or liveproxy working on many Python capable machines (computer, OpenWRT router, Enigma2 set top box, etc.) to get a constant stream URL for websites, streams that use variable stream URL addresses (including tokens, expiration time, etc.).
i’m hoping there’s a way to use this to stream youtube music live streams to echo dots? so i can stream lofi girl youtube stream to multiple echos