4

I'm developing some speech recognition app. I need to recognize words when the phone is ringing, but to do this I must cancel the speakers contribution to the microphone. So i want the microphone to ignore all audio coming from the speakers.

I've found that AcousticEchoCanceler is used for VoIP apps to cancel the echo, but I've tried to use it, and there's no difference when a tone is ringing on my phone.

I'm reading the audio from an AudioRecord object called 'recorder', and then applying the AcousticAudioCanceler

boolean isAvailable = AcousticEchoCanceler.isAvailable(); 
if (isAvailable) { 
    AcousticEchoCanceler aec = AcousticEchoCanceler.create(recorder.getAudioSessionId());
    if(!aec.getEnabled())
         aec.setEnabled(true);
    Log.d("AEC", " AEC enabled : " + aec.getEnabled() + " . Has control: " + aec.hasControl()); 
}
else
    Log.d("AEC", " AEC is not available");

I'm getting the same input when applying the AcousticCanceler and when not applying it. Why? Maybe it doesn't control the audio when coming from another application? I need it to work cancelling any output from the speakers, independently from which app they come from.

Furthermore, is AcousticAudioCanceler the only way to do this? I mean, it just works on Android Jelly Bean, and I need it to work on all devices... Thanks in advance

Hartmut Pfitzinger
  • 2,304
  • 3
  • 28
  • 48
Miquel
  • 307
  • 1
  • 4
  • 15

1 Answers1

2

Your approach is good. But as you already noted AcousticEchoCanceler was added in API level 16. Furthermore, manufacturers are not forced to implement it. So, on various devices with API level >=16 AcousticEchoCanceler.isAvailable() yields false.

Fortunately, this doesn't necessarily mean that there is no echo cancellation at all. Since you use AudioRecord you can choose MediaRecorder.AudioSource.VOICE_COMMUNICATION as input which was added in API 11 and typically has an active noise reduction as well as echo cancellation.

Unfortunately, this is also not guaranteed to work, so if you absolutely need it or need your app to work with API <=10 then you have to implement echo cancellation on your own.

Hartmut Pfitzinger
  • 2,304
  • 3
  • 28
  • 48
  • 1
    Indeed, I am observing many modern (even flagship) devices with Lollipop on do not expose the AcousticEchoCanceler. e.g ON a 2nd Gen Motorola Moto X running 5.1 AcousticEchoCanceler.isAvailable() returns false. Unbelievable really – Dean Wild Sep 07 '15 at 14:42