对于应用,我们需要从两个不同的音频源录制。一个麦克风是一个特殊的(喉咙)麦克风,它带有与麦克风的iPhone耳机相同的连接器。
在第二个频道,我们想录制环境声音,如果我们可以在iPhone和iPad的内置麦克风上同时录制,那么最好的事情就是我们从喉咙麦克风耳机录制。
这有可能吗?还有其他提示吗?
答案 0 :(得分:2)
操作系统目前只允许应用程序一次连接到一个音频源路由。在iOS设备上录制2声道的唯一方法是使用Apple USB转Lightning接口(较旧型号的相机连接套件),带有标准USB立体声ADC或带有多个麦克风输入的音频混合面板。
答案 1 :(得分:2)
我在Apple库上找到了一些关于如何从不同麦克风端口选择数据源的常见问题解答,这些可能会有所帮助:
https://developer.apple.com/library/ios/qa/qa1799/_index.html
iOS 7为开发人员提供了更多选择特定内置麦克风的灵活性。
使用iOS 7中引入的API,开发人员可以执行诸如查找代表内置麦克风的端口描述,定位特定麦克风(如“前”,“后”或“底部”)等任务,设置您选择的麦克风作为首选数据源,将内置麦克风端口设置为首选输入,如果硬件支持,则甚至选择首选麦克风极坐标模式。见AVAudioSession.h。
清单1演示了应用程序如何找到代表内置麦克风的AVAudioSessionPortDescription,找到前麦克风(在iPhone 5或其他具有前置麦克风的设备上),将前麦克风设置为首选数据源并设置内置麦克风端口作为首选输入。
清单1演示输入选择。
#import <AVFoundation/AVAudioSession.h>
- (void) demonstrateInputSelection
{
NSError* theError = nil;
BOOL result = YES;
AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];
result = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&theError];
if (!result)
{
NSLog(@"setCategory failed");
}
result = [myAudioSession setActive:YES error:&theError];
if (!result)
{
NSLog(@"setActive failed");
}
// Get the set of available inputs. If there are no audio accessories attached, there will be
// only one available input -- the built in microphone.
NSArray* inputs = [myAudioSession availableInputs];
// Locate the Port corresponding to the built-in microphone.
AVAudioSessionPortDescription* builtInMicPort = nil;
for (AVAudioSessionPortDescription* port in inputs)
{
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic])
{
builtInMicPort = port;
break;
}
}
// Print out a description of the data sources for the built-in microphone
NSLog(@"There are %u data sources for port :\"%@\"", (unsigned)[builtInMicPort.dataSources count], builtInMicPort);
NSLog(@"%@", builtInMicPort.dataSources);
// loop over the built-in mic's data sources and attempt to locate the front microphone
AVAudioSessionDataSourceDescription* frontDataSource = nil;
for (AVAudioSessionDataSourceDescription* source in builtInMicPort.dataSources)
{
if ([source.orientation isEqual:AVAudioSessionOrientationFront])
{
frontDataSource = source;
break;
}
} // end data source iteration
if (frontDataSource)
{
NSLog(@"Currently selected source is \"%@\" for port \"%@\"", builtInMicPort.selectedDataSource.dataSourceName, builtInMicPort.portName);
NSLog(@"Attempting to select source \"%@\" on port \"%@\"", frontDataSource, builtInMicPort.portName);
// Set a preference for the front data source.
theError = nil;
result = [builtInMicPort setPreferredDataSource:frontDataSource error:&theError];
if (!result)
{
// an error occurred. Handle it!
NSLog(@"setPreferredDataSource failed");
}
}
// Make sure the built-in mic is selected for input. This will be a no-op if the built-in mic is
// already the current input Port.
theError = nil;
result = [myAudioSession setPreferredInput:builtInMicPort error:&theError];
if (!result)
{
// an error occurred. Handle it!
NSLog(@"setPreferredInput failed");
}
}
在iPhone 5上运行时,清单1将生成以下控制台输出:
There are 3 data sources for port :"<AVAudioSessionPortDescription: 0x14d935a0, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Bottom>"
(
"<AVAudioSessionDataSourceDescription: 0x14d93800, ID = 1835216945; name = Bottom>",
"<AVAudioSessionDataSourceDescription: 0x14d938d0, ID = 1835216946; name = Front>",
"<AVAudioSessionDataSourceDescription: 0x14d93a10, ID = 1835216947; name = Back>"
)
Currently selected source is "Bottom" for port "iPhone Microphone"
Attempting to select source "<AVAudioSessionDataSourceDescription: 0x14d938d0, ID = 1835216946; name = Front>" on port "iPhone Microphone”
UPDATE 14 Nov
使用前面的代码我可以在iPhone上设置特定的内置麦克风来录制声音,现在我正在尝试经常更换iPhone上的特定麦克风以模拟立体声录音。