Live data from Hacker News

Ask HN: How do browsers isolate internal audio from microphone input?

news.ycombinator.com

51–60 of 106 posts

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#51
post #28
post #13

Earlier quoted context omitted.

It just seems more logical for the OS to do that, rather than the application. Basically every application that uses microphone input will want to do this, and will want to compensate for all audio output of the device, not just its own. Why does the OS not provide a way to do this?

On mac/iOS, you get this using the AVAudioEngine API if you set voiceProcessingEnabled to true on the input node. It corrects for audio being played from all applications on the device.

This has certainly made conference calls significantly more usable. I feel like it must have come around during 2020, because I feel like pre-covid I would go around BEGGING everyone I did calls with to get a headset, because otherwise everyone else's voice would echo back through their microphone 0.75s later. Today I recently realized I could just literally do calls out loud on my laptop mic and speaker and somehow it works. Nice to know why!

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#52
post #28

Earlier quoted context omitted.

On mac/iOS, you get this using the AVAudioEngine API if you set voiceProcessingEnabled to true on the input node. It corrects for audio being played from all applications on the device.

My first thought in reading the question was “if your browser is doing that, your platform architecture has… some room for improvement”.

Having room for nontrivial improvement is, to be fair, a normal state of affairs for platforms.

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#53
post #45

Earlier quoted context omitted.

> Why does the OS not provide a way to do this? Some do. But you need to have a strong-handed OS team that's willing to push everybody towards their most modern and highly integrated interfaces and sunset their older interfaces. Not everybody wants that in their OS. Some want operating systems that can be pieced together from myriad components maintained by radically different teams, some want to see their API's/inte…

> Some do Which Operating systems do this?

As others have noted, this is trivial for most macOS and iOS apps to opt in to.

Frankly, I imagine its also available at the system level on Windows (and maybe Android and Linux) but probably only among applications that happen to be using certain audio frameworks/engines.

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#54
post #41

Earlier quoted context omitted.

I agree with that, but the point I'm trying to make is that audio i/o handling is pretty complicated and application specific. The idea I'm challenging is that "any app that wants microphone input wants this" is dubious. I'd say it's only a small number of audio applications that care about mic input want background noise reduced - and it makes sense for this to be configured per-input stream. Really what would be ni…

I'm honestly having trouble thinking of a case where I wouldn't want this. I'm sure there are some niche cases, but in those cases, the application can specifically request that the OS turn off audio isolation.

Live video or audio chat is basically the only time you do want this. Granted, that’s a big chunk of microphone usage in practice, but any time you are doing higher fidelity audio recording and you have set up the inputs accordingly you absolutely do not want the artefacts introduced by this cancellation. DAWs, audio calibration, and even live audio when you’ve ensured the output cannot impact the recording all would want it switched off.

Default on vs default off is really just an implementation detail of the API though, as you say.

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#55

Earlier quoted context omitted.

I'm honestly having trouble thinking of a case where I wouldn't want this. I'm sure there are some niche cases, but in those cases, the application can specifically request that the OS turn off audio isolation.

Live video or audio chat is basically the only time you do want this. Granted, that’s a big chunk of microphone usage in practice, but any time you are doing higher fidelity audio recording and you have set up the inputs accordingly you absolutely do not want the artefacts introduced by this cancellation. DAWs, audio calibration, and even live audio when you’ve ensured the output cannot impact the recording all would…

> Live video or audio chat is basically the only time you do want this.

If I'm recording a voice memo, or talking to an AI assistant, I would want this. Basically everything I can imagine doing with a PC microphone outside of (!) professional audio recording work.

That last case is important and we agree there needs to be a way to turn it off. I think defaults are really important though.

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#56

The technical term that you're looking for is acoustic echo cancellation[1]. It's a fairly common problem in signal processing, and comes up in "simple" devices like telephones too. [1] https://www.mathworks.com/help/audio/ug/acoustic-echo-cancel...

I seem to remember analog telephone lines used a very simple but magic-looking transformer-based circuit of some sort for this purpose. Presumably that worked because they didn’t need to worry about a processing delay?

That's slightly different. analog phone lines suffer from 'line echo', which is an echo generated by the phone line itself - because the same pair of wires is used for signals traveling in both directions. If you're thinking of the 'hybrid' , which connects the phone line to the speaker and mic, that matches the impedence of each of the three pairs of wire (to the mic, speaker, and phone line) to avoid generating echo in the first place. But they weren't perfect (and echo could be generated at other points in the line) so later, digital electronics was used to do first "echo suppression" (just zero any signal below certain magnitude) and then echo cancellation, which is very similar to acoustic echo cancellation (an AEC can probably do anything an LEC can do, but the LEC is less capable).

I'm not aware of anyone doing echo cancellation using an analog circuit, but that doesn't mean no-one did. I guess it's theoretically possible but I don't see how the adaption could work.

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#57

It's called Acoustic Echo Cancellation. An implementation is included in WebRTC included in Chrome. A FIR filter (1D convolution) is applied to what the browser knows is coming out of the speakers; and this filter is continually optimized to to cancel out as much as possible of what's coming into the microphone (this is a first approximation, the actual algorithm is more involved).

Remember that convolution is multiplication in the frequency domain, so this also handles different responses at different frequencies, not just delays

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#58
post #13

Earlier quoted context omitted.

It just seems more logical for the OS to do that, rather than the application. Basically every application that uses microphone input will want to do this, and will want to compensate for all audio output of the device, not just its own. Why does the OS not provide a way to do this?

> Why does the OS not provide a way to do this? Some do. But you need to have a strong-handed OS team that's willing to push everybody towards their most modern and highly integrated interfaces and sunset their older interfaces. Not everybody wants that in their OS. Some want operating systems that can be pieced together from myriad components maintained by radically different teams, some want to see their API's/inte…

[flagged]

Re: Ask HN: How do browsers isolate internal audio from microphone input?

#59
post #45

Earlier quoted context omitted.

> Some do Which Operating systems do this?

As others have noted, this is trivial for most macOS and iOS apps to opt in to. Frankly, I imagine its also available at the system level on Windows (and maybe Android and Linux) but probably only among applications that happen to be using certain audio frameworks/engines.

It doesn't seem to me that module-echo-cancel in Pulseaudio completely meets the requirements here (only one source), but it looks close, and seems in general like where you would implement something like this.

1. https://www.freedesktop.org/wiki/Software/PulseAudio/Documen...

Post reply on HN