I have AcousticEchoCanceler working for VoIP calls for every other device type I've tried, but not on any Samsung device. The device reports AcousticEchoCanceler being available but it simply does nothing.
What I've got:
acousticEchoCanceler.setEnabled(true);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
AudioTrack
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
Has anyone got AcousticEchoCanceler to work on a Samsung device?
I had the same issue recently. The most important part for me was to use audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION) before creating the AudioRecord.
Next the AudioRecord was created with :
mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, mSamplingRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, audioRecordBufferSize);
And finally create and enable the NS and AEC :
mNoiseSuppressor = NoiseSuppressor.create(mAudioRecord.getAudioSessionId());
if (mNoiseSuppressor != null) {
int res = mNoiseSuppressor.setEnabled(true);
}
mAcousticEchoCanceler = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId());
if (mAcousticEchoCanceler != null) {
int res = mAcousticEchoCanceler.setEnabled(true);
}
The AudioTrack doesn't need to be associated to same Audio session ID than AudioTrack (I suppose it should be done automatically).
I had tried this code a few years ago and remember that it worked. Can't say how it will fare with the latest devices.
int audioSource = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
int sampleFreq = 16000;
int numChannels = 1;
int numBytesPerSample = 2;
int channelConfig = numChannels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO;
int audioFormat = numBytesPerSample == 2 ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT;
int bufSize = AudioRecord.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
if (bufSize == AudioRecord.ERROR_BAD_VALUE || bufSize == AudioRecord.ERROR) {
return;
}
AudioRecord audioInRecord = new AudioRecord(audioSource, sampleFreq,
channelConfig, audioFormat, bufSize);
if (audioInRecord.getState() != AudioRecord.STATE_INITIALIZED) {
return;
}
boolean aecAvailable = AcousticEchoCanceler.isAvailable();
if (aecAvailable) {
AcousticEchoCanceler instance;
if((instance = AcousticEchoCanceler.create(audioInRecord.getAudioSessionId())) != null) {
instance.setEnabled(true);
Log.d(TAG, "AEC enabled");
} else {
Log.d(TAG, "AEC disabled");
}
}
Try these lines:
if (AcousticEchoCanceler.isAvailable() && WebRtcAudioUtils.isAcousticEchoCancelerSupported()) {
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With