androidwebrtcmicrophonewebrtc-android

WebRTC Android echo cancellation


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?


Solution

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