July 25th, 2024

Reverse-engineering my speakers' API to get reasonable volume control

James Vaughan is reverse-engineering powered speakers' API to create a custom volume control solution, as their excessive volume levels complicate adjustments. He plans to build a physical volume knob using an ESP32 board.

Read original articleLink Icon
FrustrationInterestAppreciation
Reverse-engineering my speakers' API to get reasonable volume control

James Vaughan discusses his experience with new powered speakers that have excessive volume levels, making it challenging to achieve precise volume control. He typically uses only about 10% of the speakers' volume range, leading to difficulties when adjusting volume through standard controls on devices like his phone or computer. To address this, he is reverse-engineering the speakers' API to create a custom volume control solution.

After discovering the speakers have an undocumented HTTP API, Vaughan explored their web interface and found endpoints for reading and writing volume levels. Despite his efforts, he was unable to locate a setting to adjust the maximum volume directly. Instead, he decided to build a custom web page with a slider that allows him to control the volume within a more manageable range. He set up a small server using Bun to handle requests and ensure the volume does not exceed a safe level.

Vaughan's current solution works but he aims to create a physical volume knob for more convenient control. He plans to use an ESP32 board with a rotary encoder for this project, incorporating features like haptic feedback for a better user experience. He expresses enthusiasm for returning to hardware electronics projects as he develops this new volume control system.

AI: What people are saying
The discussion around James Vaughan's project to create a custom volume control for powered speakers reveals several common themes and concerns among commenters.
  • Many users experience issues with excessive volume levels on their devices, leading to frustration and the need for alternative volume control methods.
  • Several commenters suggest exploring existing open-source projects or products that could enhance the volume control experience.
  • There is a preference for passive speakers and separate amplifiers over active speakers due to concerns about e-waste and flexibility in upgrading components.
  • Some users express interest in the technical aspects of integrating physical controls with digital systems, highlighting the potential for innovative solutions.
  • Concerns about security in IoT devices and the complexity of modern audio systems are also raised, indicating a desire for better user control and understanding.
Link Icon 33 comments
By @laurencei - 7 months
Hey OP - if your thinking about a smart knob with haptic feedback etc - check this open source project out that you can build yourself - its amazing:

https://github.com/scottbez1/smartknob

Video demo here: https://www.youtube.com/watch?v=ip641WmY4pA&t=1s

By @christina97 - 7 months
For those considering buying speakers: (1) do it, (2) get passive ones and a separate amp. Honestly it’s such a mature market that buying these active speakers just creates e-waste. Keep the e-waste to the amp. You can get really solid speakers for $300 and a cheap amp with BT for $50-100, replacing them basically independently depending on your needs.
By @radicality - 7 months
Seems like the author moved from a “speakers + networked amp” setup, to a one where with active speakers where everything is built-in.

When I was buying speakers for my apartment some time ago, I was similarly considering going for the all-in-one options like this, but I’m glad I didn’t. I prefer the “dumb passive speaker + networked amp”, as it allows you to pick / replace / upgrade the separate components. Went for the KEF LS50, and for the amp Lyngdorf TDAI-1120. And that’s despite KEF having the all-in-one active version of those speakers. Very happy with my choices!

By @rectang - 7 months
> Those methods either give me a tiny slider that I can only use 10% of or about 15 steps where the jump from step 3 to step 4 takes the speakers from “a bit too quiet” to “definitely bothering the neighbors” levels.

Volume controls need to be logarithmic, not linear.

To a first degree approximation, everybody gets this wrong.

By @jitl - 7 months
Pro-tip for embedding JS in an HTML string in a Typescript file: you can get full typecheck etc for your embedded JS snippet if you write it as a top-level function in your file, and then interpolate the function into your template.

This works because function.toString() in modern runtimes gives you back fully parse-able input source.

You need to make sure you don’t reference anything outside the function, but it’s generally nicer overall than JS-in-string.

Then you treat it as an IIFE. Example:

    function globalJS() { document.write('hi') }
    const html = `<script>(${globalJS})()</script>`
I use this technique for calling AppleScript-flavored-JS from NodeJS too.
By @rahimnathwani - 7 months
I know it is tangential, but this about his old system caught my attention:

  With that system, I could set the amplifier’s analog volume knob such that the max volume out of the streamer corresponded to my actual maximum preferred listening volume, giving me access to the full range of Spotify or AirPlay’s volume controls.
Assuming an analog input, this might result in a noticable quality reduction at low volumes.
By @kogir - 7 months
While I’m all for physical controls, especially ones that self-adjust to reflect the state of the remote device at all times, I wonder if the author just doesn’t know you can finely adjust volume in iOS control center by force/long pressing and then dragging.
By @whynotmaybe - 7 months
You could check the m5stack dial for your next step.

A rotary knob with an integrated esp32.

https://shop.m5stack.com/products/m5stack-dial-esp32-s3-smar...

By @Dwedit - 7 months
What the hell browser makers... Make it so that file:// URLS are extremely locked down and doesn't have enough rights to even fetch files in the same directory (or even itself), yet grant localhost URLs full permissions...

There's a reason why local web applications aren't a collection of HTML and JS files, and are instead full copies of the Chromium browser.

By @possibleworlds - 7 months
Nice speakers! I'm guessing the model, if correct here are some spins for those interested https://www.erinsaudiocorner.com/loudspeakers/jbl_4329p/

Weird you can't limit digital output. I also listen mostly at low volumes and have the same issue. Part of the reason I chose Sonos is this is built in across all products, alongside an effective loudness toggle. This has been particularly helpful with some little Genelec 8010s I use as desktop speakers plugged into a Sonos Port.

By @xyst - 7 months
Why do speakers even expose a web api in the first place? It’s just easily available without any security?

Hope this person segmented this device away from other devices. The lack of basic security in the IoT space is astounding to me.

By @tgtweak - 7 months
Can anyone recommend a good open source software that allows you to cast using all the popular protocols to an rpi? Feels like the "smart" part of these smart speakers and devices seems to be what dies first. I've got a 4 year old pioneer receiver that has built in Chromecast and it simply stopped working (likely deprecated API/sdk) with no updates to fix it. Likewise there's tons of great amplifiers and receivers/speakers out there that could easily be updated to support modern streaming and speaker aggregation with minimal e-waste.

My favorite "smart" speaker in the house is a very old (~20 years) Altec Lansing 2.1 speaker kit that has a (sadly now discontinued) Chromecast audio plugged into it's headphone in.

Edit: found this which looks to fit the bill - https://github.com/balena-io-experimental/balena-sound

By @KolmogorovComp - 7 months
This begs the question, why buy oversized speakers of which you can only use 10% of the range instead of smaller speakers?

Is the sound quality better when not approaching to maximum volume?

By @dkga - 7 months
I love this type of posts, and I’m amazed the speaker exposes its API like this.

The kid in me thinks there could also be a way perhaps to transmit audio through this (or another) API? (very low chance, but…)

By @illusive4080 - 7 months
I struggled with volume control on my computer, it’s always too coarse. I found out that you can hold Option+Shift when pressing the volume button on Mac to do more fine grained adjustments.
By @Jerrrrrrry - 7 months

  // Yes, this is JavaScript embedded in HTML embedded in TypeScript.


  // I only recently learned that you can reference elements by ID this way.
  // It's kind of horrible but also I love it on tiny pages like this.
You have to kind of embrace the duality of every moment.

  -Spencer Dinwiddie
By @torphedo - 7 months
Wow, I never thought speakers would connect to the network, let alone be running Linux and a webserver for a hidden interface. Honestly, I thought speakers still weren't any more complicated than "convert this digital signal into a signal playable by the driver" with a volume knob.
By @kefabean - 7 months
In a similar vein, I was delighted to discover that my rather elderly Audiolab M-DAC (used as a pre-amp) exposes its master volume control over USB digital input when plugged into a RPi.

Although I don't use USB for audio (rather buggy) the control interface works perfectly.

I duly created a websockets API that allows me to remotely control the volume over wifi via a phsyical rotary controller. Allows me to conceal all the hifi equipment in a cupboard upstairs but remotely control it from a knob downstairs in the kitchen.

Like the OP I also implemented volume limits to prevent accidental damage to the speakers (primarily from twiddles by little fingers)....works a treat!

By @NixCald - 7 months
Fantastic, this could be iterated on by setting it up as a custom airplay speaker with re-mapped volume thresholds.

https://github.com/mikebrady/shairport-sync

By @magxnta - 7 months
I have this issue with my Echo next to my bed. Even on vol 1 it’s too loud for me.

So, instead of using the Spotify alexa skill, I have to use my phone and connect it via bluetooth, so I can turn down the volume on my phone in addition to using the quietest volume on the Echo.

By @JustinAiken - 7 months
I clicked on this article with so much excitement and hope… ah darn, not my speaker.

Sonos volume control remains broken in their new (forced) app update, “reasonable control” on the roadmap for two months out

By @hilbert42 - 7 months
I wish someone would solve the opposite problem in PCs and laptops—that of too little audio gain. Designers never leave any gain in reserve for when audio input levels are too low.

Why do they do this? The problem is so obvious that you'd reckon they're doing it to deliberately annoy users.

The problem doesn't stop there, the lack of gain with Bluetooth is notorious. Almost every Bluetooth device I own has insufficient gain, franky it's a damn nuisance. The audio in the two sound bars that I own is so low on some audio material that I'm thinking of pulling them apart to see if I can find an op amp and increase its feedback resistor to obtain more gain. I should NOT have to do this.

Let me give you an example, the audio levels on many YouTube videos can be all over the place. Often the audio can be 6 to 10 dB below what it ought to be, thus it's impossible to listen on a laptop's speakers, especially so when one is listening in a location where the background noise is high.

What's wrong with the designers who design this digital stuff, don't they ever use the equipment themselves?

Haven't they ever seen a traditional radio or HiFi where the volume potentiometer is off at the 7 o'clock position, 12 noon is the maximum volume with a nominal one volt input signal or a radio station that's using normal levels of modulation, and the reserve gain is the range from the noon position to the 5PM one?

Do I have to say it again? The reserve gain is for when the input signal is lower that it ought to be. The world is not ideal, audio signals can be far from ideal—even from high tech companies like Google.

Occasionally help comes along, VLC has settings that allow the gain to be set to over 100℅ but I've often had situations where even VLC hasn't had the necessary reserve.

I've come to the conclusion the designers and programmers of this digital equipment haven't a clue about how ordinary amplifiers work. Or they have never taken the trouble to find out. They just assume a 16-bit input has 65536 levels and that's the range. Full stop! They never give consideration to what happens when the peak audio input covers perhaps less than one third that range of bits.

To get enough volume I've even had to use the audio equalizer, that's when one has been available, and often there is not. To get the extra gain I slide all sliders to maximum. Having to do this frequently is an ergonomic nightmare.

This is what happens when the arrogant digital world is too prowd to take a leaf out of the analog world—the world that managed to get these issues right about a century or more ago.

By @kopirgan - 7 months
This runs in your laptop? Very interesting.
By @Scaevolus - 7 months
Do the speakers require the Content-Type header to be set? If not, POST wouldn't require CORS permissions.
By @ly - 7 months
I think the article incorrectly states that KEF is owned by Harman, I can only find evidence on the contrary.
By @somat - 7 months
On my todo list is to build my own set of network attached speakers. superficially, it does not appear too hard, that is, seemingly possible for even my very limited mechanical integration skills.

BOM: a halfway nice powered speaker with an integral amp and a single board computer. mount the sbc onto the speaker. then use a audio server to ship the sound around. I am a huge obsd fanboy so I would use sndiod but the linux ones(pipewire?) would probably be better for the task.

The main thing stopping me from doing it is that it turns out I dislike dumping sound into the atmosphere, nothing wrong with it, I just don't enjoy blasting music. so I just stick to my headphones, and think about it once in a while.

By @nubinetwork - 7 months
My cheap bestbuy tv is the same way... 0-100, and anything above 10 is extremely loud...
By @doctorvaughan - 7 months
I love this. Thanks for posting.

Your Father and Mother must be very proud of you.

By @msephton - 7 months
Nigel Tufnel: The numbers all go to eleven. Look, right across the board, eleven, eleven, eleven and...

Marty DiBergi: Oh, I see. And most amps go up to ten?

Nigel Tufnel: Exactly.

Marty DiBergi: Does that mean it's louder? Is it any louder?

Nigel Tufnel: Well, it's one louder, isn't it? It's not ten. You see, most blokes, you know, will be playing at ten. You're on ten here, all the way up, all the way up, all the way up, you're on ten on your guitar. Where can you go from there? Where?

Marty DiBergi: I don't know.

Nigel Tufnel: Nowhere. Exactly. What we do is, if we need that extra push over the cliff, you know what we do?

Marty DiBergi: Put it up to eleven.

Nigel Tufnel: Eleven. Exactly. One louder.

Marty DiBergi: Why don't you just make ten louder and make ten be the top number and make that a little louder?

Nigel Tufnel: [pause] These go to eleven.

- This Is Spinal Tap (1984)

By @jamesbfb - 7 months
That position of the couch infuriating! And yes I bet you moved that lovely looking couch back after the photo :)