3

I would like to implement voice and video calling in android. I used this example project as reference: Amazon Kinesis Video Streams Android WebRTC SDK Problem is that the microphone picks up the remote sounds which results in an extreme echoing effect. We use this version:

org.webrtc:google-webrtc:1.0.30039

The AudioManager is in this mode:

audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(false);

This is what we tried without any effect:

WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler();
WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true);
WebRtcAudioUtils.useWebRtcBasedAutomaticGainControl();
WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(true);
WebRtcAudioUtils.useWebRtcBasedNoiseSuppressor();
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);

and this:

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation2", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googDAEchoCancellation", "true"));

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googTypingNoiseDetection", "true"));

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAutoGainControl", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAutoGainControl2", "true"));

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression2", "true"));

audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAudioMirroring", "false"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googHighpassFilter", "true"));

I'm really lost here. How can I activate echo cancellation in android?

prechtelm
  • 43
  • 1
  • 3

1 Answers1

2

Use below methods of JavaAudioDeviceModule.class

setUseHardwareAcousticEchoCanceler(false)       
setUseHardwareNoiseSuppressor(false) 

(For reference, please have a look into createJavaAudioDevice() of PeerConnectionClient.java - Checkout official android example on googlesource.com You can also check GitHub project of Somesh (https://github.com/TheSomeshKumar/AndroidWebRTCGradle).

abhishek kumar gupta
  • 2,189
  • 6
  • 35
  • 56
  • 1
    Still no success. Anything else I can try? I use Samsung devices for test calls, on both echo cancellation works in other apps. – prechtelm Jun 22 '20 at 19:51
  • Hi @prechtelm Run the code(after making setUseHardwareAcousticEchoCanceler(false) and setUseHardwareNoiseSuppressor(false) from Somesh's Github project (https://github.com/TheSomeshKumar/AndroidWebRTCGradle) and check whether you are getting echo on your test devices or not – abhishek kumar gupta Jun 23 '20 at 06:51
  • 3
    Thanks a lot for the input! That helped me a lot! My solution looks like this: Just use `WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);`, `WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true);`and `WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(true);` and for the JavaAudioDeviceModule use: `setUseHardwareAcousticEchoCanceler(false)` and `setUseHardwareNoiseSuppressor(false)`. All other parameters reduce AEC or make AEC not working at all. (I really don't get why) – prechtelm Jun 23 '20 at 11:28
  • Remember one thing which is related to `SAMPLING RATE`. WebRtc AECM module by default provides processing only on `8000HZ`, `16000HZ`. If you are working on `48KHz`, then I would prefer to check this tutorial for only WebRtc Audio Processing on any device. Different hardware has different tendencies towards APM(Audio Processing Module). Please visit [Android-Audio-Processing-Using-WebRtc](https://github.com/mail2chromium/Android-Audio-Processing-Using-WebRTC). – Muhammad Usman Bashir Feb 10 '21 at 09:41
  • @MuhammadUsmanBashir thanks for the comment. The complete library `implementation 'org.webrtc:google-webrtc:1.0.32006'` includes the WebRtc APM? – Tomer Petel Jun 16 '22 at 05:55
  • 1
    @TomerPetel If you will use AudioTrack which is normally known as `Audio-Channel` or `Audio-Engine`, then you can basically use the `powers` of APM and it will give you the results of your expectations. If you want to develop your own WebRtc SDK to get access to APM on the Java layer to process your own data, then you can visit my series to develop WebRtc from scratch: (https://medium.com/@BeingOttoman/compile-and-build-webrtc-library-for-android-platform-3216416263fd) , (https://medium.com/@BeingOttoman/simplest-webrtc-debugging-development-environment-for-linux-3d4e4aed54f3) – Muhammad Usman Bashir Jun 20 '22 at 05:54