强制iPhone麦克风作为音频输入 [英] Forcing iPhone Microphone as Audio Input

查看:831
本文介绍了强制iPhone麦克风作为音频输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序(目前专门针对iPhone),要求应用程序仅从iPhone内置麦克风录制音频(即使插入了耳机/耳机),以及在耳机播放(我们假设现在插入了耳机)。

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

我想知道目前是否可以使用可用的API?如果是这样,有人可以说明我该如何做这件事吗?

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?

谢谢!

推荐答案

我相信这个问题的答案是'不'。我使用iPhone 4和新到iOS 4 AVFoundation进行实验,重点关注 AVCaptureDevice 类。

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:

NSLog(@"%@", [AVCaptureDevice devices]);

因此要求列出可用于捕获音频和/或视频的所有设备。没有插入耳机,我得到:

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:

(
    "Back Camera",
    "Front Camera",
    "iPhone Microphone" 
)

插入耳机I得到:

(
    "Back Camera",
    "Front Camera",
    Headphones
)

因此iPhone麦克风一旦耳机就会从可用的AVCaptureDevices列表中删除变得可用。为了进一步探讨这一点,我添加了一些代码来获取可用音频设备的AVCaptureDevice实例并打印其唯一ID。对于将自己标识为iPhone麦克风的设备和将自己标识为耳机的设备,我得到:

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:

com.apple.avfoundation.avcapturedevice.built-in_audio:0

在我看来,显而易见的是两个设备不能具有相同的唯一ID,因此显然它是改变其状态的相同设备。虽然AVCaptureDevices有很多用于设置状态的东西,但它仅限于焦点,曝光,闪光和白平衡等视觉效果。

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.

这篇关于强制iPhone麦克风作为音频输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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