我在这里看到已经有人提过相同的问题:
我查了一下这个线程,但没有回应。
但是,请问有人知道为什么AVAudioRecorder可能无法使用AirPods作为应用程序中录制音频的输入设备吗?我已经通过内置麦克风以及其他蓝牙设备(Beats、廉价的蓝牙扬声器电话等)进行了音频录制,但在使用AirPods时,我无法捕捉音频。
此外,在准备录制时,我会循环遍历可用的输入,并强制输入为蓝牙设备(请参见下面的代码),在这种情况下是AirPods。同样,在所有其他蓝牙设备上工作,但不适用于AirPods。
您有什么想法吗?任何关于我们做错了什么的指导都将非常感激。这让我非常恼火。
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord withOptions:audioSession.categoryOptions|AVAudioSessionCategoryOptionAllowBluetooth
error:&error];
[audioSession setActive:YES error:nil];
NSLog(@"Data sources: %@", [audioSession availableInputs]);
// Data sources: ("<AVAudioSessionPortDescription: 0x1706071b0, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Bottom>",
"<AVAudioSessionPortDescription: 0x170611bd0, type = BluetoothHFP; name = Dan\U2019s AirPods; UID = 50:32:37:E0:90:37-tsco; selectedDataSource = (null)>"
for (AVAudioSessionPortDescription *desc in [audioSession availableInputs]){
NSLog(@"Port desc: %@", desc.portType);
// Loop: 1) Port desc: MicrophoneBuiltIn
// 2) Port desc: BluetoothHFP
if (desc.portType == AVAudioSessionPortBluetoothHFP) {
NSLog(@"Trying to change preferred input");
NSError *error;
BOOL didSet = [audioSession setPreferredInput:desc error:&error];
NSString *didSetString = didSet ? @"True" : @"False";
NSLog(@"Post change preferred input: %@, error: %@", didSetString, error);
// Post change preferred input: True, error: (null)
}
}
.record
切换到.playAndRecord
确实解决了我的AirPods问题。你有任何想法吗?我测试过的其他蓝牙耳机(超过10个)都可以使用.record
。我很高兴修复如此简单,但担心根本原因没有得到解决。 - bclymer