Most android smartphone has two mics. One at the top and One at the bottom. When I start capturing audio, some phones capture audio from the top mic while others from the bottom mic. Then there are some phones which are capturing audio from both mics.
The problem I am facing is the attenuation in the audio quality and voice diminishing when I have placed my phone in front of me on the table with the screen side facing upward. Some phones capture from the bottom mic, which provides good quality, while others capture from the top mic, and this causes issues.
Hopefully, you guys have understood the scenario. Now following are the things I need your help for
I have tried using Whatsapp on the same devices, and it captures audio perfectly, but it doesn't happen in my case.
Thanks.
So after researching and getting some valuable answers from Stackoverflow. I finally succeeded in setting up the desired mic to capture input audio.
This question How to select physical microphone and audio recording path in Android helped me get the desired information.
I run this code:
val audioDeviceInfo = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)
var audioInfo :AudioDeviceInfo? = null
for (dev in audioDeviceInfo) {
if(dev.address == "bottom"){
Log.d("TAGAudioInfo", dev.id.toString())
audioInfo = dev
}
}
So what does this code do?
This code gets all the input audio devices currently attached to your android phone. The returned list includes built-in and external devices, such as microphones. Now the important thing is the AudioDeviceInfo
address
attribute. This attribute tells us about the physical position of the input device.
For the mic, there are two primary addresses.
So what next after getting this information?
Next step is to set this mic as preferred device to capture audio. The setting of the mic is easy to do as following:
audioRecord.setPreferredDevice(audioInfo);
To cross-verify, you can use the OboeTester Application available on Google Playstore, which allows you to select any source to capture audio.
So, in this way, I resolved this issue of capturing audio from desired mic.
Also, please note that this varies from manufacturer to manufacturer of devices. Even after selecting the bottom
microphone, some devices still use both mics to capture audio. But this doesn't affect me as my primary purpose of capturing audio from the bottom microphone is resolved.