I have been working on a VoIP application (usually operated in speaker mode). The problem I am facing is that the behavior of audio recording is quite different for different models of smartphones.
Let me add a picture and explain it from there:

enter image description here

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

  1. How do I determine which mic is used for audio capturing? I have set the settings as follows:
    enter image description here
  2. 我有already tried separating different channels (L/R)元和compute RMS to determine which channel is loud and map that to a specific mic. Still, unfortunately, this didn't work, as energy was the same on both media元.它推断,当我们 Select 立体声中的一个频道时,它从一个麦克风中捕获数据,然后将其以立体声形式(L,R)存储在PCM_16bit中.
  3. I tried using CHANNEL_IN_MONO, but the mic direction (which the mic is used for audio capturing) is still not fixable or detectable.

我试过在同样的设备上使用Whatsapp,它可以完美地捕捉音频,但在我的情况下却不是这样.

谢谢.

推荐答案

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.

  1. 底端
  2. Back (which is usually the mic at the top)

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.

Android相关问答推荐

如何检测HitTest是否命中给定的网格对象?

如何处理谷歌未经证实的应用程序拒绝?

对支持哪些数据存储区方法感到困惑

在androidStudio中,如何使用带有ResolutionStrategy的ResolutionSelector而不是setTargetResolve()?

制作圆形SupportMapFragment

使用lazyColumn迁移paging3的旧代码

如何使用滑行加载媒体的专辑封面?

Android Compose 为什么 Checkbox 在父对象可点击时需要 onCheckChanged?

Android AGP 8 + Gradle 8 + Kotlin 1.8 导致 Kapt 出错

java.lang.ExceptionInInitializerError -- 原因:java.lang.NullPointerException

Jetpack Compose:如何绘制异形边框?

在 Jetpack Compose 中对齐行项目

为什么集成React Native时compileSdkVersion错误?

为片段设置主题

Compose Accompaniist Pager 中的 TabRow/Tab 重组问题

可组合的可见性不随状态变化而变化

为什么我在 Jetpack Compose 中被警告可选修饰符参数应该具有默认值修饰符?

房间实时数据:启动时崩溃

可扩展性 Qt 5.15 Android

Android全屏AlertDialog