Is it possible to receive audio input from iPhone\'s built-in microphone, and play that audio through a Bluetooth headset, at the same time?
My goal is to always use
You can choose a specific microphone while playing audio through a bluetooth audio device.
// set audio session category to .playAndRecord. use do-catch if you need error-handling
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker, .allowBluetoothA2DP, .allowBluetooth])
// check if currentRoute is set to a bluetooth audio device
let btOutputTypes: [AVAudioSession.Port] = [.bluetoothHFP, .bluetoothA2DP, .bluetoothLE]
let btOutputs = AVAudioSession.sharedInstance().currentRoute.outputs.filter { btOutputTypes.contains($0.portType) }
// if so, set preferred audio input to built-in mic
if !btOutputs.isEmpty {
let builtInMicInput = AVAudioSession.sharedInstance().availableInputs?.filter { $0.portType == .builtInMic }.first
try? AVAudioSession.sharedInstance().setPreferredInput(builtInMicInput)
} else {
// set default input
try? AVAudioSession.sharedInstance().setPreferredInput(nil)
}
try? AVAudioSession.sharedInstance().setActive(true)
or you can follow detailed instruction from here https://developer.apple.com/library/archive/qa/qa1799/_index.html
It is not possible to receive audio input from iPhone's built-in microphone, and play that audio through a Bluetooth headset, at the same time