2

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.

  • Hello! I know that this is not accepted. But for a long time I cannot resolve the issue. Could you help me? I would be very grateful. I can't find AirPods Pro in my area. Could you just open up my small xcode project and test it please? https://stackoverflow.com/questions/69851479/audio-files-wont-play-with-airpods-pro-on-ios-15 –  Nov 13 '21 at 19:05
  • This I believe is a hardware issue — AirPod Pros can't record at a sample rate higher than 16kHz, hence why the software doesn't allow it. In case you're interested in the opposite problem — downsampling — I found this great [post](https://stackoverflow.com/questions/39595444/avaudioengine-downsample-issue#) – Afika Nyati Nov 14 '21 at 20:10

1 Answers1

0

Try calling the following before starting your AVAudioEngine instance

AVAudioSession.sharedInstance().setCategory(.playAndRecord)
try AVAudioSession.sharedInstance().setPreferredSampleRate(44_100)
Eric
  • 16,003
  • 15
  • 87
  • 139
  • Unfortunately, it didn't resolve the issue. My hunch is that the sample rate of the AirPods hardware is 16kHz, so we're rate-limited to that. In the documentation for `AVAudioSession.sharedInstance().setPreferredSampleRate()` they mention that, "The hardware sample rate to use. The available range is device dependent and is typically from 8000 through 48000 hertz." – Afika Nyati Sep 10 '20 at 16:29