I have had the same issue recently. The most important part for me was using audioManager.setMode (AudioManager.MODE_IN_COMMUNICATION) before creating AudioRecord.
Then AudioRecord was created using
mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, mSamplingRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, audioRecordBufferSize);
And finally, create and activate 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); }
AudioTrack need not be associated with the same audio session identifier as AudioTrack (I assume this should be done automatically).
Kervala
source share