Created
June 13, 2019 23:59
-
-
Save ydnar/912b88f19bc2d937f3b7ffe03354484f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks https://amorten.com/blog/2017/ios-bluetooth-and-microphone-input/ | |
func configure() { | |
// ... | |
let session = AVAudioSession.sharedInstance() | |
let sampleRate = 48000.0 | |
do { | |
try session.setCategory( | |
.playAndRecord, // Simultaneously play and record audio | |
mode: .default, // .voiceChat somehow breaks with .allowBluetoothA2DP, making microphone not work | |
options: [ | |
.mixWithOthers, // Mix audio with other apps | |
.allowBluetoothA2DP, // Allow the use of Bluetooth devices like AirPods (DO NOT USE .allowBluetooth, which forces audio to 16kHz | |
.defaultToSpeaker, | |
.allowAirPlay, | |
] | |
) | |
try session.setPreferredSampleRate(sampleRate) | |
print("Configured audio session: \(session.sampleRate)") | |
} catch { | |
print("Error configuring audio session: \(error)") | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tried this but not working for my AirPods Pro. Playing audio route to AirPods is fine, but recording by AirPods is failed, still using iPhone builtin microphone.