Home » Android » debugging – How to solve Echo in Android webRTC audio when connected to multiple audio channels

debugging – How to solve Echo in Android webRTC audio when connected to multiple audio channels

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have been using libjingle to make peer connection between four users to share data and also start audio channel.
It works ok most of the times but have issues of echo from one user which makes the call very unstable and hard to listen to users.

I have tried adding

this.mediaConstraints.optional.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true"));
this.mediaConstraints.optional.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true"));

I am adding these constraints in the optional parameters in case I add these in mandatory it disconnects the call and throws onRenegotiationNeeded method.

I have listed some cases such as :

1) This might be the cause of 1 user is in loudspeaker(or earphone is loud enough) that voice registers in mic and creates the echo. (But sometimes it happens without this reason as well)

2) There may be 1 audio channel registered twice and creating a reverb effect with same user sending data channel twice. (Cant find how to debug this, I count the audio channel and they are normal)

3) Two users are in the same room and echo happens (This is a normal case which happens but it’s not a concern as its unavoidable)

I am looking for suggestions or solutions in case someone else got into such issue with Android webRTC library.

implementation 'io.pristine:libjingle:[email protected]'

The library I am suing is this, but I also found out that latest webRTC official library is updated recently, would migrating to that solve any such issue ?

The latest library which I found is:

implementation 'org.webrtc:google-webrtc:1.0.22672'

Any help would be highly appreciated.

Thanks

How to&Answers:

Newer versions of WebRTC has WebRtcAudioUtils class which you can use for WebRTC based Acoustic echo cancellation (AEC).

Here you have two choices either you can use built-in AEC or WebRTC based AEC.

//Disable built-in AEC even if device supports it
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);

or

//Enable built-in AEC if device supports it"
 WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(false);

I think pristine doesn’t maintain android WebRTC library anymore. So I would suggest you use new WebRTC libraries hosted by Google because many bug fixes are only available in new version of Google-hosted WebRTC libraries which is at the time of writing is

implementation 'org.webrtc:google-webrtc:1.0.22920'

I had a hard time migrating my pristine based WebRTC project to Google based WebRTC libraries because many classes are deprecated and some of them are not even in the newer version of WebRTC. You can check my GitHub project which is a client of AppRTC where I’m using WebRTC prebuilt libraries from Google OR Checkout official android example on googlesource.com. In PeerConnectionClient class they are also using WebRtcAudioUtils to toggle Echo as well as Noice, High pass filter etc.