Ios AirPods不作为语音记录器应用程序的输入源工作
由于某些原因,我的语音记录应用程序不会使用AirPods作为输入源。开始录音时,输入源从AirPods变为iPhone麦克风。我不知道怎么修 Eddie, 如果你仍然有问题,请参阅我的类似帖子,我们最终解决了问题Ios AirPods不作为语音记录器应用程序的输入源工作,ios,swift,Ios,Swift,由于某些原因,我的语音记录应用程序不会使用AirPods作为输入源。开始录音时,输入源从AirPods变为iPhone麦克风。我不知道怎么修 Eddie, 如果你仍然有问题,请参阅我的类似帖子,我们最终解决了问题 连接AirPod时,有两种方法可以录制和播放音频。对于这两种情况,我们都将使用AVAudioSessionCategoryPlayAndRecordcategory。诀窍是管理AVAudioSessions选项集 添加.allowBluetoothA2DP选项。这将允许您通过AirPo
连接AirPod时,有两种方法可以录制和播放音频。对于这两种情况,我们都将使用
AVAudioSessionCategoryPlayAndRecord
category。诀窍是管理AVAudioSession
s选项集
.allowBluetoothA2DP
选项。这将允许您通过AirPods收听音频,并使用内置麦克风录音.allowBluetooth
选项。使用此选项,您可以在播放过程中使用AirPods录制音频。但在这种情况下,音频质量会降低首先,我捕获可用的输出源
let currentOutputSource = AVAudioSession.sharedInstance().outputDataSource
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP])
if let currentOutputSource = currentOutputSource {
// Then i set known output source to input source.
try AVAudioSession.sharedInstance().setInputDataSource(currentOutputSource)
}
try? AVAudioSession.sharedInstance().setActive(true)
它对我有用
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP]
if let headphones = AVAudioSession.sharedInstance().availableInputs?.first(where: { $0.portType == .bluetoothHFP || $0.portType == .bluetoothA2DP || $0.portType == .headphones }) {
try? AVAudioSession.sharedInstance().setPreferredInput(headphones)
}
try? AVAudioSession.sharedInstance().setActive(true)
您设置了什么音频会话类别和模式?参考:嘿,埃迪,我只是想看看你是否能解决这个问题。我们最近遇到了同样的问题,但也无法确定遗漏了什么。