Record audio from AirPod Pros at higher sample rate than 16kHz

Viewed 485

Is it possible to record audio through the microphone of AirPod Pros at a sample rate higher than 16kHz?

I'm tapping into the microphone bus using audioEngine:

let node = audioEngine.inputNode
let recordingFormat = node.outputFormat(forBus: 0)

node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { [unowned self] (buffer, _) in
    self.request!.append(buffer)
}

audioEngine.prepare()
do {
    try audioEngine.start()
} catch {
    fatalError("\t[Error] There was a problem starting speech recognition")
}

It seems as though the default sample rate (found in recordingFormat) is 16000Hz, and I've had difficulty specifying a higher sample rate.

This particular sample rate returns an audio recording with fairly low quality compared to a recording from the iPhone microphone, which has a sample rate of 44100Hz.

1 Answers

Try calling the following before starting your AVAudioEngine instance

AVAudioSession.sharedInstance().setCategory(.playAndRecord)
try AVAudioSession.sharedInstance().setPreferredSampleRate(44_100)
Related