仅使用iPhone中的顶级麦克风 [英] Using only the top mic in an iPhone

查看:174
本文介绍了仅使用iPhone中的顶级麦克风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,iPhone上有2个麦克风. 1位于音频插孔旁边的顶部附近,另一个是您要讲话的麦克风. 默认麦克风似乎是您要讲话的麦克风.

As far as I know there are 2 mics on an iPhone. 1 is near the top next to the audio jack, and the other one is the microphone you speak into. The default mic seems to be the one you speak into.

人们如何以编程方式选择使用哪种麦克风?我正在为我的应用程序使用Core Audio.

How does one choose programmatically which microphone to use? I'm using Core Audio for my app.

基本上,我想使用顶级麦克风进行录音.目前,当我录制底部麦克风时,正在使用该麦克风.有没有办法覆盖默认麦克风设置?

Basically I want to use the top mic for recording. Currently when I record the bottom mic is being used. Is there a way to override the default mic setting?

我知道可以通过以下方法覆盖默认扬声器设置.

I know that one can override the default speaker setting by the following.

UInt32 yes = YES;

AudioSessionSetProperty( kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,        sizeof(UInt32),   &yes );

iPhone上的麦克风有什么相似之处吗?

Anything similar for microphone on an iPhone?

谢谢.

推荐答案

使用AVAudioSession获取可用的输入.

Use AVAudioSession to get available inputs.

NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs);

"<AVAudioSessionPortDescription: 0x14554400, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Back>"

然后使用这些输入之一获取可用的数据源,就像这样.

Then use one of these inputs to get availableDataSources, like this.

NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs[0].dataSources);

"<AVAudioSessionDataSourceDescription: 0x145afb00, ID = 1835216945; name = Bottom>",
"<AVAudioSessionDataSourceDescription: 0x145b1870, ID = 1835216946; name = Front>",
"<AVAudioSessionDataSourceDescription: 0x145b3650, ID = 1835216947; name = Back>"

我们可以看到此iPhone上实际上有三个麦克风:顶部,顶部,底部和底部.现在,您可以设置首选的数据源.

AVAudioSessionPortDescription *port = [AVAudioSession sharedInstance].availableInputs[0];
for (AVAudioSessionDataSourceDescription *source in port.dataSources) {
    if ([source.dataSourceName isEqualToString:@"Back"]) {
        [port setPreferredDataSource:source error:nil];
    }
}     

希望这对您有帮助 祝您编码愉快!

Hope this helps you Happy Coding!!!

这篇关于仅使用iPhone中的顶级麦克风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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