如何选择外接麦克风 [英] How to select external microphone

查看:128
本文介绍了如何选择外接麦克风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功编写了一个使用AVAudioRecorder的iOS简单录音应用程序.到目前为止,如果已将其插入耳机插孔,则可与内部麦克风或外部麦克风一起使用.如何选择通过USB闪电端口"连接的音频源?我必须深入研究Core Audio吗?

I've successfully written a simple recording app for iOS that uses AVAudioRecorder. So far it works with either the internal microphone or an external microphone if it's plugged in to the headphone jack. How do I select an audio source that is connected through the USB "lightning port"? Do I have to dive into Core Audio?

具体地说,我正在尝试连接Apogee Electronics ONE USB音频接口.

Specifically I'm trying to connect an Apogee Electronics ONE USB audio interface.

推荐答案

使用AVAudioSession,获取availableInputs.返回值是AVAudioSessionPortDescriptions的数组.遍历数组,检查portType属性以匹配您的首选端口类型,然后使用端口描述来设置preferredInput.

Using AVAudioSession, get the availableInputs. The return value is an array of AVAudioSessionPortDescriptions. Iterate through the array checking the portType property to match your preferred port type, then set the preferredInput using the port description.

let audioSession = AVAudioSession.sharedInstance()
if let desc = audioSession.availableInputs?.first(where: { (desc) -> Bool in
    return desc.portType == AVAudioSessionPortUSBAudio
}){
    do{
        try audioSession.setPreferredInput(desc)
    } catch let error{
        print(error)
    }
}

Objective-C:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSString *preferredPortType = AVAudioSessionPortUSBAudio;
for (AVAudioSessionPortDescription *desc in audioSession.availableInputs) {
    if ([desc.portType isEqualToString: preferredPortType]) {
        [audioSession setPreferredInput:desc error:nil];            
    }
}

这篇关于如何选择外接麦克风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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