meshenger-android icon indicating copy to clipboard operation
meshenger-android copied to clipboard

About echo cancellation

Open TurboTu opened this issue 2 years ago • 12 comments

When two device output via speakphone and there will be much echo. Is there any method to add echo cancellation process?

TurboTu avatar Apr 24 '23 08:04 TurboTu

I found webrtc has aec module, is there any hint about how to integrate it into the code

TurboTu avatar Apr 24 '23 09:04 TurboTu

I have some local code to enable AEC, but it is not tested yet.

mwarning avatar Apr 24 '23 10:04 mwarning

I can do some test, can u share the code, or some tips how to ? I have tried use android.media.AudioTrack(not webrtc AudioTrack) and Speex to cancel the echo, and it worked. But I have no idea how to add the code into this project.

TurboTu avatar Apr 24 '23 19:04 TurboTu

In my code, I should set sample rate at 8k and single track, enable aec, and use Speex at audio encoder and decoder, but webrtc has no entry. And in this project, I also tried disable the hardware echo cancellation and other code like below: WebRtcAudioUtils.setDefaultSampleRateHz(8000) WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(true) WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true) WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true) var audioDeviceModule = JavaAudioDeviceModule.builder(App.getInstance()) .setUseHardwareAcousticEchoCanceler(false) .setUseHardwareNoiseSuppressor(false) .setSampleRate(8000) .createAudioDeviceModule() var initializationOptions = PeerConnectionFactory.InitializationOptions.builder(App.getInstance()) .createInitializationOptions() PeerConnectionFactory.initialize(initializationOptions) factory = PeerConnectionFactory.builder() .setAudioDeviceModule(audioDeviceModule) .setVideoEncoderFactory(encoderFactory) .setVideoDecoderFactory(decoderFactory) .createPeerConnectionFactory()

but all failed

TurboTu avatar Apr 24 '23 19:04 TurboTu

I would want to try this: https://webrtc.googlesource.com/src/+/refs/heads/main/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java#535

mwarning avatar Apr 25 '23 05:04 mwarning

I have seen this code, dump the stream into a tmp file(like the aecDump method), and do aec ops? Am i right?

TurboTu avatar Apr 25 '23 05:04 TurboTu

Yes. But I would leave out the recording stuff.

mwarning avatar Apr 25 '23 10:04 mwarning

Any detailed information? I don't understand? I searched over the internet, not too much talked about aec based on webrtc.

TurboTu avatar Apr 25 '23 10:04 TurboTu

The line with setSamplesReadyCallback seems to be for recording audio. Let's leave out that line out if you plan to make a merge request.

mwarning avatar Apr 25 '23 18:04 mwarning

I'll have a try, thanks

TurboTu avatar Apr 26 '23 10:04 TurboTu

Did you get echo cancellation to work?

mwarning avatar May 10 '23 02:05 mwarning

I have added the JavaAudioDevice code. But it does not seem to work for me.

mwarning avatar May 29 '23 19:05 mwarning