在 iOS 中通过蓝牙播放时从内置麦克风录音 [英] Recording from Built-In Mic when Playing through Bluetooth in iOS

查看:89
本文介绍了在 iOS 中通过蓝牙播放时从内置麦克风录音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 iPhone 的内置麦克风接收音频输入,并同时通过蓝牙耳机播放该音频?

Is it possible to receive audio input from iPhone's built-in microphone, and play that audio through a Bluetooth headset, at the same time?

我的目标是始终使用内置麦克风作为输入设备,即使输出设备是耳机,因为内置麦克风在我的用例中更方便.

My goal is to always use the built-in microphone as the input device, even if the output device is a headset, because the built-in microphone is more convenient in my use cases.

当输出设备是有线耳机(例如 iPhone 捆绑的耳机)时,我知道如何实现我的目标.我直接插上有线耳机,调用如下方法:

I know how to achieve my goal when the output device is a wired headset, like the one that comes bundled with an iPhone. I simply plug the wired headset in, and call the following method:

- (void)selectBuiltInMicrophone
{
    AVAudioSession *session = [AVAudioSession sharedInstance];
    for (AVAudioSessionPortDescription *port in session.availableInputs)
        if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
            NSError *error;
            [session setPreferredInput:port error:&error];
            break;
        }
}

通过调用上述方法,输入设备将从有线耳机的麦克风切换到iPhone的内置麦克风,而输出设备不受影响,因此iPhone将从内置麦克风录音并通过有线播放耳机.这正是我所期望的.

By calling the above method, the input device will be switched from the wired headset's microphone to iPhone's built-in microphone, while the output device remains unaffected, so the iPhone will record from the built-in microphone and play through the wired headset. This is what I expect.

问题是,当耳机是蓝牙耳机时,此方法不起作用.如果我把蓝牙耳机连接到iPhone,然后调用上面的方法,内置麦克风就变成了输入设备,这很好,但输出设备也会变成iPhone的接收器,这很糟糕.

The problem is, this method does not work when the headset is a Bluetooth one. If I connect a Bluetooth headset to the iPhone, then call the above method, the built-in microphone will becomes the input device, which is great, but the output device will also be changed to iPhone's receiver, which is bad.

蓝牙耳机的输入和输出似乎是锁定在一起的:你要么两个都用,要么都不用.我的目标真的不可能吗?或者有没有办法克服明显的限制?

It seems that the input and the output of a Bluetooth headset are locked together: you either use both of them, or you use none of them. Is my goal really impossible? Or there exists a way to overcome the apparent limitation?

推荐答案

无法同时从 iPhone 的内置麦克风接收音频输入,并通过蓝牙耳机播放该音频

  1. 有一种预防措施,您可以像使用对讲机一样使用.
  2. 你必须创建两个会话.意味着在录制音频时,您必须启用带有录制和播放功能的音频会话.
  3. 在播放时,您必须将选项设置为 audiosession (allowingBluetooth) .
  4. 在录制时,您必须设置录制和播放.

这篇关于在 iOS 中通过蓝牙播放时从内置麦克风录音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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