Hacker News new | past | comments | ask | show | jobs | submit login
Sonos smart speaker controller API and CLI written in Rust (github.com)
200 points by mlang23 20 days ago | hide | past | web | favorite | 106 comments

I'm done with Sonos after they removed the ability to play music straight off the phone onto the speakers. The only way now to play music is via a service like Spotify or if you set up an mp3 server via SAMBA.

They keeping cutting features and making their older speakers obsolete. I'm furious as an early adopter of Sonos that they are essentially bricking my older speakers or making them useless for no reason. I can't Airplay to them either because they are older. I can see in the next year or so them completely rendering my speakers useless, which is unethical. I'm done with them.

Seems like a good time to plug my favorite FOSS alternative, Snapcast.



I use shairplay[0] to stream from an iOS/macOS device, and Mopidy[1] with the Iris UI[2] to play server-side from your music collection, Spotify, or other internet radio.

[0] https://github.com/juhovh/shairplay

[1] https://mopidy.com/

[2] https://github.com/jaedb/Iris#readme

My "speakers" are cheapo Bluetooth speakers with a raspberry pi attached to the back. Works beautifully and reliably. If the old Sonos devices have line in, maybe this is a way to continue using them?

Also, if you're on Linux, PulseAudio can do this pretty much out of the box.

Likewise, I shifted Sonos to the "dead to me" category when they removed from their desktop software almost all abilities to configure the rooms/speakers. Gotta use the iOS/Android app now. Oh, and the app really wants you to make a Sonos account and sign in, for no customer-serving reason at all.

From here on it'll be a Pi connected to an amplifier and speakers that won't try to subvert my will simply to listen to music.

What setup are you considering using with the pi and speakers? I'm also interested in doing this, but haven't found a good OSS solution (yet).

For the moment it's a Pi 4 + Hifiberry Digi+ Pro with Volumio software. Volumio provides a pretty decent web UI, automatic scanning of connected USB storage, Airplay (v1), and a Spotify Connect plugin. There are also other plugins but I haven't looked into them too closely.

I also liked Roon Bridge on the Pi (and felt the audio output was slightly improved, although made no effort to counter the placebo effect) but couldn't quite justify the cost.

If you have a Linux box like a Pi, you can expose that machine's audio device over the network with PulseAudio, and if you have that enabled, it'll autoconfigure and work like any other PulseAudio device.

I used to share my DAC between my laptop and my desktop this way. Whenever I plugged my headphones in, it'd default to them on the local device, and the remote would default to the network device. I could walk away from my desktop while playing something, and it'd continue playing on whichever I had my headphones plugged into.

I’m using a Raspberry Pi with shairport-sync, a SPDIF HAT and a Maestro-50 amplifier (that I got for cheap) and am really happy with it. I even route TV audio through it and have a IR sensor for remote control.

i bought a play:1 years ago for the bathroom, mostly just to play radio or stream to it while getting ready in the morning. the account thing upset me too. i haven't updated the firmware or the sonos app just so i wouldn't have to create a stupid account.

i like the ikea symfonisk speakers but won't buy them for the same reason.

I have 3 sonos units - two of their speakers and one "amp" which drives in ceiling speakers.

The hardware is great, but their constant software updates are TERRIBLE!

I would never a product from them again and I tell everybody who comments / asks on our home set-up the same thing.

Want to play music but they want you to update? Guess what? No option but to update right away.

The app consistently changes UX and REMOVES functionality making it extremely frustrating.

Feels like a company that is in harvest mode and driving towards irrelevance.

I have many more Sonos units than that. The majority are Connect:AMP devices (connected to the in-wall speakers my home came with), but some are their standalone speaker units.

For me, the biggest gripe is that its a pain in the arse to get networking to work when your configuration gets more complex than an "average person" living in a small house/apartment. Especially when there are multiple ways to make a wireless network connection across your property, and/or you have multiple subnets. At this point, I can bring down half my home network by connecting a new Sonos box, before I've changed some of its default configurations (which you can't do until you have it fully setup and connected).

My second biggest gripe is that they don't make rack-able multi-channel units. I'd love to rack one or two of these in my wiring closet instead of having a stack of Connect:AMPs on shelves.

Denon apparently now has a Sonos competitor that at least partially solves the second issue. I'm curious to see how it compares, but I've got enough Sonos gear that I'm not really ready to seriously consider replacing it. (And once all my stuff is setup, it does work rather painlessly.)

They do not require you to install updates to play music. Updates are never mandatory, except that if you update a zone player then you must update the controller to control it. If your controller is ahead of the ZP that works fine.

> They do not require you to install updates to play music.

This is flat out false.

Far too often, I open the app and just want to play something. It prohibits me from doing so until I update software.

It is an incredibly user hostile and annoying behavior in an otherwise good product.

It's because you have your zone player(s) set to automatically update. I've ignored updates for months on end and never had the first trouble with doing so.

My brother asked me for a audio solution for a project of his and proposed Sonos. His use case was basically connecting a phone to the speaker system.

I explained why I wouldn’t take it and my main argument is that any “smart” device isn’t exactly reliable in the long term, be it missing updates for old hardware, cutting out features, servers that stop working etc.

He got a simple Amp with a single volume knob now and some decent passives. Phone connects via line cable.

He may be interested in devices which can connect to a phone via bluetooth and to amps via standard audio cables. They basically turn any old amp/speakers setup into a wireless streaming one, and they work quite well.


I use something exactly like this product (an old one from monoprice actually I believe). Simply plugs into the back of a 2.1 speaker set I have. Guests at my place love it, they can easily just connect to the Bluetooth and play through speakers. Pretty seamless. Not sure of any quality drop, my speakers aren't the best.

Right, I use a TT-BA08 to plug my cheap cable headphones in (since most new Smarthones ditched the 3.5mm), which connects to another one which is only a sender (and has no volume controls). That sender receives a line-out of a little analog mixer into which a PC and other devices plug in.

This is quite nice, because it allows me to stand up and walk around while the PC continues its audio playback.

Thanks for the tip! I knew these already so I did propose it to him back then, but it seems he was fine with just a cable.

Let’s see how the future of smartphones pans out, when it comes to audio jacks tho : )

He maybe like me and doesn't like the quality drop of bluetooth depending on the rest of the setup obviously.

If the setup can support aptX, quality should be reasonable.

There's no version for Mac or Windows, but linux users can use noson -> http://janbar.github.io/noson-app/. Play music straight off your computer.

Wow, thanks for sharing this. I'm on Linux myself but you can find builds for Windows, OS X, and Android here: https://github.com/janbar/noson-app/releases

I don't understand why HNers are willing to buy smart speakers when we make such a fuss lamenting the fact that nobody makes dumb TVs anymore. Buy dumb speakers and connect them to a little PC so you can run whatever software you want.

Pure convenience here. Sure, 20 year old me would hate me for putting cloud connected smart speakers in my home but I'm not 20 anymore and available time was replaced by available money. I honestly looked and would have paid more for a fully local speech to text hub with basic apps and a nice API but there simply wasn't anything that looked like it wouldn't annoy the living hell out of me. I don't want to setup raspberry pis around my house, maintain and update weird open source stacks and whatnot. I want to stream stuff to speakers, control devices around the house through voice and sometimes use other convenience functions.

Fully realizing the hit on privacy, I understand the thing enough and, more importantly, trust my particular manufacturer enough that it simply outweighs that concern for me.

The Sonos experience was amazing. Great sounds, really simple to use, being able to play music in different rooms is cool, etc, and just plugging in the speakers into the power outlet without any extra cords really made for a great experience. It's much cleaner not having to worry about running speaker wire everywhere, or having laptops or rpis everywhere.

But they brick their older hardware or render them purposefully useless so as far as I'm concerned they are evil as fuck now.

A smart TV doesn't offer any value add for me - I have a chromecast, I have a recorder. By contrast, a smart speaker in the kitchen does add value. Being able to use Siri to set a timer, play music or add something to the shopping list when up to my elbows in cake mixture is of benefit.

The point of Sonos (afaik) is to have audio playing throughout your home, which is harder to set up on your own than just a speaker playing music.

HN users are not all alike. You will find some users purchasing IOT/smart devices, and some hating on them.

FWIW it seems that it is Apple, not Sonos, who killed off the ability to stream to Sonos directly from an iOS device.

I can use AirPlay with my brand new Sonos speaker.

Are you talking about some other way to stream it?

It used to be the case that your phone showed up as a source if you were using the Sonos app on that phone. You could play podcasts or any files that were stored on your device. Now you can't. They added AirPlay to newer hardware but older hardware can't do it. For example my ZP100, the original Sonos player (which still is supported 15 years after it was first marketed), cannot do AirPlay.

fwiw it works just fine on Android... it can play files directly from the phone in the Sonos app or by casting from any other app

For airplay on my old ones i run


on a raspberry pi, works great

Thank you for posting this. I didn't know about it, and this post made my day. Gonna get this setup for my older Sonos speakers this evening.

no problem enjoy!

Same. 99% of my usage is through AirConnect

That and the fact that you can only activate them by using an online service. Screw that, if I buy a device like that I expect it to simply work. No grafted on service models. Too bad for Sonos.

Are you sure the old hardware is capable of supporting Airplay? I thought it didn’t have the processing power required.

Except for Airplay my several years old speakers work fine. I’m happy with the support so far.

I was initially excited when I saw that Ikea was now offering speakers that could be integrated into the Home Smart (Trådfri) system.

Then I saw that they were Sonos-based, and immediately noped out of buying any. I'm not keen on buying something if the vendor can yank features (or worse, brick the gear they sold like Logitech did) at their whim.

The Ikea symfonisk speakers that are basically rebranded cheap Sonos speakers support Airplay 2. So Apple users can still stream from their devices towards the speakers. At 100$ a piece that's not bad.

With no line in port I returned both of mine. Since I'm not already invested in Sonos that's too much lock-in for my liking. Should you have to keep paying to keep using?

yeah, similiar experience. I've got a play 3 and the think it's quite a pain. I would never buy a sonos or recommend it to anyone, it's a poorly supported walled garden which only introduces features to the newer speakers and is not even working that well.

I have a 3 (among a few other Sonos products) and it’s literally the easiest thing to use.

Maybe it’s because I’m no longer in the business of amassing a horde of mp3s and instead use Spotify and amazon music.

Maybe it’s because I haven’t opened the Sonos app in months, and instead use Alexa’s integration or Spotify’s integration to play my music.

I'm in the same camp as you. I love Spotify and have 0 interest in amassing and maintaining my own music collection any more. Ever since they added the ability to play directly from the Spotify app to Sonos I couldn't be happier.

All (9) but one of my Sonos speakers get used regularly without issue. I do with Airplay worked with them, but I've recently drank the Kool Aid of streaming music after much resistance.

I do wish our Play One could proxy Airplay to the others.

The speakers that support Airplay can proxy Airplay to the others, with caveats: you can group a speaker that's playing Airplay with speakers that don't support AirPlay and it'll play back on all the speakers just fine. The big catch is that the speaker that's actually receiving the AirPlay stream has to keep playing it; if you ungroup that speaker, it'll stop AirPlay playback on all the grouped speakers. Not sure whether that's an actual technical limitation or just a limitation in Sonos's UI, though.

I wish AirPlay behaved more like Line In does (on speakers that support that), where the Line In devices become available to any speakers on the network.

> I'm done with Sonos after they removed the ability to play music straight off the phone onto the speakers.

Did they ever support this? They don't have built in Bluetooth, and I think they only talk NFS and Samba(?) for audio servers.

The other integrations over UPnP/SOAP (IIRC) are for sending it audio URLs or instructions to play Spotify, Google Play, etc.

Some of these pieces might have been pulled out with recent API updates?

I don't have firm details, only forum hearsay, and I'd love to find out what's actually going on with Sonos' APIs.

Yes, they did support it until very recently.

Sounds like an iOS specific limitation? I have a mix of gen1 hardware as well as some newer stuff. Playing from Android phones still works fine even on the old hardware, though I primarily stream from Spotify or from a local Plex server

Yes, you could stream from the app to their speakers over wifi. I used it regularly.

Odd that they would do this, given there are plenty of competitors can be streamed to via Bluetooth, or HomePods which support AirPlay.

Sonos speakers support AirPlay as well.

not the older ones, which is what OP was complaining about.

I think the older ones never did support AirPlay. They has some other mechanism in an older app, but I’m not sure of it was apple or Sonos that killed that.

I was worried for a second until I realized you were talking about an iPhone. The option on Android is still there.

At first I was excited because the Sonos software stack frustrates me, but looking at source it just hits api.sonos.com. Would love to control the speakers directly on my LAN.

Their API used to allow this. It was all open protocols.

Are they starting to lock it down through API updates? If so, that's terribly unfortunate and I'll have to rethink my audio setup and future purchases.

Open, unencrypted, easy to reverse engineer with a packet sniffer. I hope it stays that way, because I built a project[1] that kinda depends on it. Should that change, my project suddenly requires a fair amount of annoying and complicated work.

[1] http://hecgeek.blogspot.com/2017/10/wall-o-matic-interface-1...

Have you tried: https://github.com/SoCo/SoCo Used it a bit seems to work most of the time

Do you know if the speakers are discoverable locally, and what protocol they use for that?

I know Apple is all mDNS (for AirPlay), I don’t know anything about Sonos though.

Sonos is (or was) mostly UPnP with some extensions... so for discovery they used SSDP https://en.wikipedia.org/wiki/Simple_Service_Discovery_Proto....

I messed around with their stack and internals for a while about ten years ago... some remnants remain




They use SOAP on UDP. I played with it a while back using Sonex https://github.com/harmon25/sonex Have a fork to make some things work under my username.


I wonder what the point of interest is with this project. Libraries for Sonos access have been available for well over a decade[1].

Is this interesting simply because a device with a well-documented API is now accessible from Rust? If not... what new information is being presented?

[1] https://github.com/topics/sonos

This would be a lot more useful with some documentation and a readme.

I was about to say the same. Never understood the "read the source" attitude. If the developer wants to gain users or maybe even get help in developing it, at least a simple installation and usage example should be there.

15 minutes work for him, would save every user 30 or more minutes.

Not going to try it because of this. A shame. Did find another interesting cli though: https://pypi.org/project/sonos-cli/

The project is 12 days old.

Maybe you could contribute instead of complaining?

I wish! All I can contribute is expressing my concerns. Don't want to be impolite, don't want to complain. Just express my concerns.

I find it quite frustrating that open source/current company projects have no or little documentation. Even for a 12 days project it is frustrating. It is just good habit that documentation is as important as code. I like to say that if it has no documentation, it does not exist (to the user/contributor). I also think that code is a way of communicating with your future self or future developers. So clear code and clear documentation is important. Code is not important to the computer, the computer does not care about naming things.

From another perspective: Whilst I am likely to spend far more time documenting than coding in my work, when I build something at home to fix a problem just for me I'm far less likely because it's for me.

In the case of this particular developer, it isn't just for themselves, but also in a different language, and they've done their best just to reflect an existing API. They've asked for pull requests.

I can understand not wanting to do the enormous amount of work of translating an API that is already pretty-much documented when I won't really see any return at all.

The funny thing about Sonos speakers is that they run STP amongst themselves. If improperly configured, this can cause unexpected STP behavior on a network, and random ports to be shut off.

Have we all started to mention the language now when we write a piece of software?

Well, it's Rust! That means it will never crash, leak memory, or be susceptible to buffer overflow exploits. Plus it's fast! You can listen to a 2-minute song in 1 minute 50 seconds!

This is golden. (And for those who aren't familiar with rust, it can leak memory and it tends to crash intead of exhibiting undefined behavior... but you could write it to listen to a 2 minute song at a faster pace :)

This also apply with all garbage collected languages. So your argument is moot.

On hacker news, people are interested in hacking. I don’t know rust so that adds a barrier to entry for me, but might be nice for a rust programmer.

I own Sonos and I program in Rust. Two interest points.

Rust is trying to get to the threshold where it's applicable in the workplace. (All but a few major companies use it.) Unlike Golang, it needs all the cheerleading it can get to push it over that hurdle.

I want to use Rust at work instead of Java.

I find Home Assistant running on a Raspberry Pi more than capable of all the automation I could possibly need with my Sonos speakers along with almost any other device you can think of.


Similar project but for Beoplay & written in Swift: https://github.com/tlk/beoplay-macos-remote-cli (shameless plug)

Docs are here if anyone is looking for what you can do: https://developer.sonos.com/reference/

I'll assume not everything is covered.

Yes, only the control API is implemented for now.

Similar project but integrates with Spotify (written in node) https://github.com/kswilster/bronos (shameless plug)

I've actually built sonos-web [1] a couple of years ago, and started to rewrite it in Rust [2], but didn't have much time to do it.

It should be a good place to start if anybody wants to extend it (:

[1]: https://github.com/denysvitali/sonos-web

[2]: https://github.com/denysvitali/sonos-web-rs

How could I make a LED light show with Sonos? I would need to get FFT data of the audio and synchronize with Sonos. Is it possible?

Love this!

If I create a group of speakers, how do I play something on them? If I have 2 speakers that are airplay-capable, Do I just pick one?

I never used Rust. Looking at the code, I see a "Cargo.toml" file that reminds me of composer.json and package.json in that it seems to contain dependencies.

Where are these pulled from? Is this the same game as with other dependency managers in that you blindly trust a tree of code written by random people?

If you still have issues with it, Cargo (Rust's package manager) has the option to use alternative package repositories, so you can host your own repository of packages[1] if you so choose. I haven't looked too far into it, so I don't know how painless it is to replace the default one or set up a mirror for packages you trust, but someone on Reddit claims to do just that at their company [2].

I wish Rust made it easier to know who the author of a package is (i.e. namespace packages so it's clear in the Cargo.toml), but I do think they've done a better job at designing crates.io than some other package repositories (i.e. npm).

[1] https://boats.gitlab.io/blog/post/2017-10-28-alternative-reg...

[2] https://www.reddit.com/r/rust/comments/9gl8p3/host_local_rep...

You list the packages and trust their authors. That's pretty much the definition of software packages - unless you've got a sandbox for dependencies. What other model do you have in mind?

They're pulled from crates.io. I suppose it works as every other dependency manager, except that you can't have a left-pad because crates can't be removed.

In this specific case, most dependencies are authored by people well-known and trusted in the community. The Rust standard library is pretty well-rounded (not compared to Python sense, but it's not like JavaScript either), so they're not something like left-pad or is-odd.

You have there an error handling crate by the second most prolific Rust compiler contributor (if the counts are correct), an OAuth client, an HTTP one, a interactive line editor (like readline), _the_ serialization library in the ecosystem with its JSON support crate, a TOML config parser, the URL parser used by Servo and a crate for determining user paths on Unix.

With cargo (Rust build tool) you don't need to use crates.io _always_ .

For instance, you can target a repository and even a specific commit like this in gour cargo.toml file:

  package = { git = "https://github.com/...../something.git", rev = "commit_hash_like_9876541_for_instance" }

You can still have your dependencies reference the source cargo packages, but overwrite it in a patch or vendor section.

Don't specify the git repo directly in dependencies unless it's an unpublished crate.

You can even host your own package registry, but I didn't think it would be worth mentioning in the context of that question.

what universe are you living in that you don't have to trust code written by randoms? nobody has the time to evaluate every transitive dependency. you take a small risk of getting hit by a car when you cross the road, and you take a small risk of a bad dependency when you want to create substantive software

How is that different from maven, apt, rpm, pacman, ports, brew, chocolatey, pip, gem, &c?

You can look at the source yourself but yes it works like every other modern programming language.

"Written in Rust". That alone makes it worthy of the frontpage.

The speakers are quite smart; the people willing to use them and get their entire life recorded by Google and Amazon - somewhat less smart. IMHO.

Sonos sells speakers that don't have any alexa or google integration.

Website: https://www.sonos.com/en-us/shop/one.html

says "Google Assistant" and "Alexa Built-in".

Sonos products have existed for years before Google Assistant or Alexa even were a thing.

I own a couple of these. Because it has multiple options for virtual assistants, nothing is running out of the box as it wouldn't know which account to use or what service to route to. You have to go through an additional setup process after setting up the speaker for music playback.

Do you know for certain that nothing is running silently out of the box? Or cannot be remotely triggered to run?

Do you know something is running / can be triggered? Someone can't prove a negative (X isn't running) as easily as a positive (X is), so the burden of proof should fall on you. Saying "yeah, but how do you know your toaster can't be remotely triggered to record you?" isn't useful.

Maybe your threat model doesn't allow any hardware with a speaker that has updates, but that's not a reason to say it's an invalid setup for everyone's threat model nor to claim that, even without evidence, it's definitely going to be abused.

Ah ok, the burden of proof is on me. Your powerful logic has defeated me and now you are safe and sound with your smart speaker which doesn't eavesdrop on you.

You can buy a One SL, Play:5, Playbar, or Playbase.

Some of Sonos' speakers have Google Assistant and Alexa, some don't. They sell more than just the One!

You could have taken a look round the site rather than just looked at one product...

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact