-
-
Save osmanzeki/ea29a69c4f515fa2de8dcbc4c599d33e to your computer and use it in GitHub Desktop.
This file contains 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