在Android上使用Oboe库同时打开两个麦克风是可能的吗?

huangapple go评论107阅读模式
英文:

Is it possible to open 2 microphones in Android at same time with Oboe library?

问题

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);

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

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.

英文:

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);

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

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.

答案1

得分: 2

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

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

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

助手 + 普通应用程序

辅助功能服务 + 普通应用程序

语音通话 + 普通应用程序

有关更多详细信息,请阅读此页面中的Android文档。

英文:

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 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:

> Assistant + ordinary app
>
> Accessibility service + ordinary app
>
> Voice call + ordinary app

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

答案2

得分: 0

实际上,即使你有两个麦克风,根据文档中的说明,同一时间内不可能拥有多个流,仅当我们谈论的是内部麦克风时,因为它们由相同的通道表示,但是如果我们谈论的是外部设备,那么有两个输入输出通道,你可以拥有两个不同的流。

英文:

in fact even if you have two microphones, from what is stated in the docs it is not possible to have more than one stream at the same time, ONLY IF we are talking about internal microphones since they are represented by the same channel, if instead we are talking about external devices then there are two input-output channels and you can have two different streams.

huangapple
  • 本文由 发表于 2020年8月12日 10:32:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63368914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定