Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC Android: sound from phone speaker is going into conference through phone mic and causing echo

In some mobile devices(like Motorola One Power - Android 10, Redmi Note 5 Pro - Android 7.1.2), sound from phone speaker is going into conference through phone mic and causing echo. This echo issue is coming only when Phone Speaker is in ON state.

I have used MODE_IN_COMMUNICATION mode of AudioManager:

mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

Also, used below audio constraints to create Audio Source by using createAudioSource() API of PeerConnectionFactory:

audioConstraints = new MediaConstraints();
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googAutoGainControl", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googHighpassFilter", "true"));
audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true"));

Any help or guidance in resolving the issue will be well appreciated.

like image 454
abhishek kumar gupta Avatar asked Jun 18 '20 11:06

abhishek kumar gupta


1 Answers

Some phones can't do hardware echo cancellation, even though they advertise it's available. Redmi Note 5 is definitely one of them, take a look at https://github.com/signalapp/Signal-Android/blob/master/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java, search for HARDWARE_AEC_BLACKLIST. So, to enable WebRTC AEC, 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

like image 117
abhishek kumar gupta Avatar answered Nov 15 '22 00:11

abhishek kumar gupta