前言
WebRTC源代码中设计了两个回声消除模块,AEC(Acoustic Echo Canceller)和AECM(Acoustic Echo Canceller Mobile),AEC是在电脑端使用的回声消除器,而AECM是在移动端使用。由于电脑与移动设备的差别比较明显,在处理速度上,编解码器的性能上和内存方面都有着较大的差异。
主体
AudioManager 设置为通话模式,如下:
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(false);
创建 PeerConnect的时候设置如下:
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler();
WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true);
WebRtcAudioUtils.useWebRtcBasedAutomaticGainControl();
WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(true);
WebRtcAudioUtils.useWebRtcBasedNoiseSuppressor();
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);
或者进行如下设置:
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"));
JavaAudioDeviceModule 创建时进行如下设置:
private JavaAudioDeviceModule audioDeviceModule;
private JavaAudioDeviceModule.Builder audioDeviceModuleBuilder;
audioDeviceModuleBuilder = JavaAudioDeviceModule.builder(ContextUtils.getApplicationContext());
this.audioDeviceModule = audioDeviceModuleBuilder
.setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
.setUseHardwareAcousticEchoCanceler(false)
.setUseHardwareNoiseSuppressor(false)
.createAudioDeviceModule();