是否可以使用双簧管库在 Android 中同时打开 2 个麦克风? [英] Is it possible to open 2 microphones in Android at same time with Oboe library?

查看:24
本文介绍了是否可以使用双簧管库在 Android 中同时打开 2 个麦克风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用谷歌的 Oboe 库为每个麦克风打开 2 个麦克风流:

I'm trying to open 2 microphone streams with google's Oboe library like this, for each microphone:

oboe::AudioStreamBuilder builder;
    builder.setChannelCount(channelCount)
            ->setDirection(isInput ? oboe::Direction::Input : oboe::Direction::Output)
            ->setSharingMode((oboe::SharingMode) sharingMode)
            ->setPerformanceMode((oboe::PerformanceMode) performanceMode)
            ->setInputPreset((oboe::InputPreset)inputPreset)
            ->setDeviceId(deviceId)
            ->setSessionId((oboe::SessionId) sessionId)
            ->setSampleRate(sampleRate)
            ->setFormat((oboe::AudioFormat) format)
            ->setChannelConversionAllowed(channelConversionAllowed)
            ->setFormatConversionAllowed(formatConversionAllowed)
            ->setSampleRateConversionQuality((oboe::SampleRateConversionQuality) rateConversionQuality)
            ;

oboe::AudioStream *oboeStream = nullptr;
oboe::Result result = builder.openStream(&oboeStream);

如您所见,deviceId 被传递给构建器.这是我通过一些 java 方法获得的麦克风 ID.我将 7 和 9 作为 ID 传递给内置麦克风和电话麦克风.问题是当我尝试启动 2 个流时:

As you can see, the deviceId is passed to the builder. This is the microphone ID that I get with some java methods. I pass 7 and 9 as ids, for built-in microphone and telephone microphone. The problem is when I try to start the 2 streams:

oboeStream.requestStart()

我在第二个流中收到此错误:

I get this error for the second stream:

E/AudioRecord: start() status -38

但是如果我尝试只打开第一个,然后只打开第二个,在 2 个不同的版本中,一切正常.那么我不能用双簧管打开 2 个麦克风流是真的吗?看起来很强大的库,应该是可以的.

but if I try to open the first one only, and then the second one only, in 2 different builds, everything works. So is it true that I cannot open 2 microphone streams with Oboe? It looks like a powerful library, it shouldbe possible.

推荐答案

大多数情况下,Android 不允许您从多个线程捕获音频.您的手机有多少输入源或使用哪个库都无关紧要.您不能同时打开两个音频流.即使两个单独的普通应用程序也无法同时访问输入源,如果您想在另一个进程捕获的流源时开始录制,则会返回错误.从 Android 10 开始,发生了一些变化.根据文档:

Android doesn't allow you to capture audio from more than one thread most of the time. It doesn't matter how many input sources your phone has or which library do you use. You can't open two audio streams at the same time. Even two separate ordinary applications don't have access to the input sources simultaneously and if you want to start recording while a stream source captured by another process an error would be returned. From Android 10 some changes occurred. According to the doc:

Android 10(API 级别 29)及更高版本强加了一个优先级方案可以在应用程序运行时在应用程序之间切换输入音频流.在大多数情况下,如果新应用获取音频输入,则之前的捕获应用程序继续运行,但接收静音.在某些情况下系统可以继续向这两个应用传送音频.

Android 10 (API level 29) and higher imposes a priority scheme that can switch the input audio stream between apps while they are running. In most cases, if a new app acquires the audio input, the previously capturing app continues to run, but receives silence. In some cases the system can continue to deliver audio to both apps.

两个流意味着两个线程,就像两个不同的应用程序.在某些情况下,两个进程可以同时捕获音频,如下所示:

Two streams mean two thread which is like two different apps. In some scenarios, two processes can capture audio at the same time like so:

助手+普通应用

无障碍服务+普通应用

语音通话+普通应用

有关详细信息,请阅读此页面安卓文档.

For more details please read this page at the Android doc.

这篇关于是否可以使用双簧管库在 Android 中同时打开 2 个麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆