Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osmanzeki/ea29a69c4f515fa2de8dcbc4c599d33e to your computer and use it in GitHub Desktop.
Save osmanzeki/ea29a69c4f515fa2de8dcbc4c599d33e to your computer and use it in GitHub Desktop.
// 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