Thursday 22 July 2021

How to select physical microphone and audio recording path in Android

I'm developing an app that records audio input from the device's microphone(s). We'd like to record unprocessed/raw audio (i.e. with no effects applied like noise suppression or automatic gain control) and also give users the option to specify which microphone (e.g. top, front, back, etc.) to use for recording.

According to Android documentation, the only way to get an input audio stream that's guaranteed to be unprocessed is by selecting VOICE_RECOGNITION on setAudioSource()

That said, what would be the correct way to choose the physical microphone to use?

In more recent API levels, there are the following methods that seem to allow for the selection of specific microphones:

  • Android 6+: AudioRecord.setPreferredDevice() accepts a target input device to use for input. We may use AudioManager.getDevices() to get a list of available microphones, but it seems it's not possible to tell the position (front, back, etc.) of the microphones returned by that method.
  • Android 11+: AudioRecord.setPreferredMicrophoneDirection() receives a direction constant that specifies the "logical microphone (for processing)". That "logical microphone" seems to map well to what I'm calling a microphone's position (front, back, etc.), but I'm not sure about how this method works in conjunction with setPreferredDevice().

Does anybody know how to achieve my goals, i.e. get unprocessed audio input while also specifying the physical microphone to use?



from How to select physical microphone and audio recording path in Android

No comments:

Post a Comment