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

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

问题描述

我正在尝试使用Google的 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个不同的版本中仅打开第一个,然后仅打开第二个,则一切正常.我不能用Oboe打开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:

助手+普通应用

无障碍服务+普通应用

语音通话+普通应用

有关更多详细信息,请在此页面Android文档.

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

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

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