Echo cancellation on recording/mixing

Skip to first unread message

Omar Jay

Aug 7, 2022, 7:00:34 PMAug 7
to discuss-webrtc
Hello, I'm writing a module to record WebRTC conversations.  My understanding is that echo cancellation can be applied to microphone inputs and also seems to be applied when audio tracks are mixed for multiple video elements in a browser.

I'd like to apply echo cancellation to an audioContext that mixes the audio tracks in my conversation.  Is this possible?

mixAudioStream(stream) {
  if (stream.getAudioTracks().length > 0 && this.audioDestination) {

The reason I want to do this is that I have a need to record 2 inputs from the same computer for 2 people talking to each other face to face, with a camera & mic facing each person.

The problem, I think, with echo isn't feedback from any speaker, because the echo is there when wearing headphones.  I think the echo is from different latency lengths from different mics.

I know there are other ways of dealing with this.  The simplest way is to have 1 shared mic between the two people.  That's probably what I'll use.  The other slightly more complex way is to use 2 analog mics combined into the same input.   Another way would be to apply echo cancellation after the video is recorded or processed.


Omar Jay

Aug 8, 2022, 11:49:25 AMAug 8
to discuss-webrtc
An update after working on this over the weekend.  I don't think the echo issue is a big problem, at least on my current hardware.  I was previously mixing the screen capture audio track with the  2nd mic track.   I'm guessing there was more overhead with that than just capturing the mics.  With 2 mic captures, there's a slight echo, but it's tolerable.

I'm also experimenting with volume detection to only capture a single mic at once.  Right now that has a lot of irritating clicking sounds from switching, but I'm thinking I can get rid of those with some sort of filter.



Aug 8, 2022, 8:17:58 PMAug 8
to discuss-webrtc
echoCancellation is important when 2 channels are expected to be captured, see

> I think the problem is getUserMedia(): When echoCancellation is set to true and channelCount is not explicitly set to 2, respectively, channelCount of audio MediaStreamTrack will always be 1. Related: When channelCount is set to 2 and echoCancellation is set to true, only silence is captured by MediaRecorder. Explicitly set channelCount to 2, echoCancellation to false in audio constraints to capture 2 channels, when available. See

In theory we should be able to use applyConstraints() on a track in a MediaStreamAudioDestinationNode or MediaStreamAudioSourceNode. I would try to apply the constraint(s) to the track before passing to Web Audio API.

Reply all
Reply to author
0 new messages