强制 iPhone 麦克风作为音频输入
我正在开发一个 iOS 应用程序(目前专门针对 iPhone),该应用程序需要仅从 iPhone 内部麦克风录制音频(即使插入耳机/耳麦),并在耳机上播放(我们假设现在已插入耳机)。
我想知道目前可用的 API 是否可以实现这一点?如果是这样,任何人都可以告诉我如何去做这件事吗?
谢谢!
I am developing an iOS application (targetted specifically for iPhone, at the moment) that requires the application to record audio only from iPhone internal microphone (even when headphone/headset is plugged in), and playback at headphone (let's assumed headphone is plugged in for now).
I am wondering if this is currently possible with the available APIs? If so, can anyone please shed some light on how do I go about doing this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我相信这个问题的答案是“不”。我使用 iPhone 4 和新的 iOS 4 AVFoundation 进行实验,重点关注 AVCaptureDevice 类。
我将以下内容添加到应用程序中:
因此,这要求列出可用于捕获音频和/或视频的所有设备。没有插入耳机时,我得到:
插入耳机时,我得到:
因此,一旦耳机可用,iPhone 麦克风就会从可用 AVCaptureDevices 列表中消失。为了进一步探究这一点,我添加了一些快速代码来获取可用音频设备的 AVCaptureDevice 实例并打印其唯一 ID。对于将自身标识为“iPhone 麦克风”的设备和将自身标识为“耳机”的设备,我得到:
在我看来,两个设备显然不能具有相同的唯一 ID,因此显然它是同一台设备改变它的状态。尽管 AVCaptureDevices 有很多用于设置状态的内容,但它仅限于视觉内容,例如焦点、曝光、闪光和白平衡。
I believe the answer to this question to be 'no'. I used an iPhone 4 and the new-to-iOS 4 AVFoundation to experiment, focussing on the AVCaptureDevice class.
I added the following to an application:
So that asks that all devices that can be used for capturing audio and/or video be listed. Without the headphones plugged in, I get:
With the headphones plugged in I get:
So the iPhone microphone drops off the list of available AVCaptureDevices as soon as the headphones become available. To probe this further, I added a quick bit of code to grab the AVCaptureDevice instance for the available audio device and to print its unique ID. For both the device identifying itself as "iPhone Microphone" and the device identifying itself as "Headphones", I got:
It would seem to me to be obvious that two devices can't have the same unique ID, so clearly it's the same device changing its state. Although AVCaptureDevices have a lot of stuff for setting state, it's limited to visual things like focus, exposure, flash and white balance.
看来确实是不可能了。
我的目标是将输出发送到蓝牙耳机并记录来自它的输入。
据我所知,我最好的选择是:“PlayAndRecord + AllowBluetoothInput”属性
(iphone 4,诺基亚 BH-214 耳机)
重要的是,根据苹果文档,当音频路由更改时,您始终必须重新覆盖音频类别!
这是我的 ROUTE CHANGE LISTENER 方法,打印:RouteChangeReasons、outputRoute、audioRout:
}
Looks like its really not possible.
My goal is to send output to bluetooth headsets and record input from it too.
As far I can see, my best options are: "PlayAndRecord + AllowBluetoothInput" property
(iphone 4, nokia BH-214 headset)
IMPORTANT thing is that according to the apple documentation, you always have to RE-override your audio category when audio route changes!
THIS IS MY ROUTE CHANGE LISTENER method, that prints: RouteChangeReasons, outputRoute, audioRout:
}
由于苹果从 7.0 开始再次更改了音频系统,我将在此处发布更新后的代码:
记住添加观察者,因为音频会话的委托也已弃用:
PS:您不需要在此处重置类别(如6.0)
Since apple changed the audio system again starting from 7.0 I'm going to post the update-ed code over here:
Remember to add observer since the audio session's delegate is deprecated too:
PS: you dont need to reset the category here (as in 6.0)
这是不可能的,我尝试用路由更改的侦听器(使用 AudioSession)来弄清楚。我的结果是:您无法单独配置输入或输出,因为 Apple 提供的类别。我尝试*PlayAndRecord,当我配对蓝牙设备时,路由更改如下:
事实上,我的蓝牙不是耳机,只是扬声器......所以对我来说没有解决方案。
It is not possible, I try to figure out with route changed listener (with AudioSession). My result is : you can't configure separately input or output because of categories provided by Apple. I try *PlayAndRecord, when I pair a bluetooth device, route change like this :
In fact, my bluetooth is not an headset, just speakers... So for me there is no solution.
我非常有信心通过您的应用程序的音频会话可以实现这一点:
深入研究这些文档:
和让我知道进展如何!
I am pretty confident this is possible via your application's Audio Session:
Dig on these docs:
And let me know how it goes!
我发现,当使用 AirPod pro 耳机并尝试录制语音邮件问候语时,即使耳机已完全连接并正在使用,手机也会使用内置麦克风。
I found that when using AirPod pro headphones and trying to record a voicemail greeting that the phone used the built in mic even though the headset was fully connected and in use.