Live data from Hacker News

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

news.ycombinator.com

31–40 of 106 posts

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

#31
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.

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

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

#32

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).

To spare a search: https://webrtc.googlesource.com/src/+/refs/heads/main/module...

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

#33
post #17
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?

How sure are you that Basically every application wants this? So should there be a flag at the os level for enabling the cancellation? How do you control that flag?

It would be trivial to pass that flag in whatever API the application calls to request access to the microphone stream.

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

#34
post #19
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?

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

The OS can have multiple sound input devices for the application to choose from, "raw" and "fuckarounded with"

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

#35

Earlier quoted context omitted.

Is there any way to apply this outside the browser? Like, is there a version of this that can be used with Pulseaudio?

To spare others from googling: https://docs.pipewire.org/page_module_echo_cancel.html https://wiki.archlinux.org/title/PipeWire/Examples#Echo_canc... If you're still on pulseaudio for some reason, it ships with a similar module named "module-echo-cancel": https://www.freedesktop.org/wiki/Software/PulseAudio/Documen...

Huh, thanks. I was interested in this probably 6-8 years ago, and when I went digging the stackoverflow answer mentioned elsewhere in this thread [0] was as far as I got. I guess the tech has progressed since then.

[0] https://stackoverflow.com/questions/21795944/remove-known-au...

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

#36
post #19
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?

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

[deleted]

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

#37
post #19
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?

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

>The OS doesn't have more information about this than applications

the OP pointed out that this only works if he uses a browser monoculture

the OS does have more information than that, it can know what is being played by any/all apps, and what is being picked up by the mic

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

#38
post #34
post #19

Earlier quoted context omitted.

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

The OS can have multiple sound input devices for the application to choose from, "raw" and "fuckarounded with"

That doesn't make sense in the context of default devices. MacOS's AVKit (or is it CoreAudio?) APIs that configure the streams created on the device makes way more sense, since it's a property of the audio i/o stream and not the devices.

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

#39
post #19
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?

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

Assuming this isn't parody, the OS doesn't have to do it automatically. Having an application grab a microphone stream and say to the OS "take this and cancel any audio out streams" might be pretty useful.

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

#40
post #37
post #19

Earlier quoted context omitted.

> Basically every application that uses microphone input will want to do this The OS doesn't have more information about this than applications and it's not that obvious whether an application wants the OS to fuck around with the audio input it sees. Even in the applications where this might be the obvious default behavior, you're wrong - since most listeners don't use loudspeakers at all, and this is not a problem w…

> The OS doesn't have more information about this than applications the OP pointed out that this only works if he uses a browser monoculture the OS does have more information than that, it can know what is being played by any/all apps, and what is being picked up by the mic

The "OS" isn't special here, apps can listen to system audio.

fwiw, you only need to know anything about outputs if you are doing AEC. Blind source separation doesn't have that problem and can just process the input stream.

Post reply on HN