I need to set up a stream from iPhone built-in microphone to headset over HFP. It works perfectly with A2DP when I configure audiosession with .allowBluetoothA2DP
option, but HFP is critical for my task, because it is much faster than A2DP. When I configure AVAudioSession with .allowBluetooth
, which actually enables the HFP on headsets, the input automatically switches to headset's microphone.
Is there any way to make it work from iPhone mic to headset over HFP?
The code below switches headset to HFP mode, but the microphone is used from headset as well.
AKSettings.bufferLength = .medium
AKSettings.defaultToSpeaker = false
AKSettings.enableRouteChangeHandling = true
AKSettings.playbackWhileMuted = true
let mic = AKMicrophone()
let mixer = AKMixer(mic)
let booster = AKBooster(mixer, gain: 2.0)
AudioKit.output = booster
mic?.start()
do {
try AudioKit.start()
// Do that after starting the AudioKit!
try? AKSettings.setSession(category: .playAndRecord, with: [ AVAudioSession.CategoryOptions.allowBluetooth ])
printInputOutputDevices()
} catch {
print("AudioKit boot failed.")
}