AcousticEchoCanceler on Samsung devices not working

吃可爱长大的小学妹 提交于 2020-05-12 11:49:42

问题


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);
  • Audio session ID passed to AudioTrack
  • Sample rate: 16k
  • Tried both mono and stereo recording
  • <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?


回答1:


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




回答2:


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");
    }
}



回答3:


Try these lines:

if (AcousticEchoCanceler.isAvailable() && WebRtcAudioUtils.isAcousticEchoCancelerSupported()) {
                WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
                WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler();
            }


来源:https://stackoverflow.com/questions/46560814/acousticechocanceler-on-samsung-devices-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!