Why does AVAudioRecorder show 8 kHz when iPhone hardware is 48 kHz?

Hi everyone,

I’m testing audio recording on an iPhone 15 Plus using AVFoundation.
Here’s a simplified version of my setup:

let settings: [String: Any] = [
    AVFormatIDKey: Int(kAudioFormatLinearPCM),
    AVSampleRateKey: 8000,
    AVNumberOfChannelsKey: 1,
    AVLinearPCMBitDepthKey: 16,
    AVLinearPCMIsFloatKey: false
]
audioRecorder = try AVAudioRecorder(url: fileURL, settings: settings)
audioRecorder?.record()

When I check the recorded file’s sample rate, it logs: Actual sample rate: 8000.0

However, when I inspect the hardware sample rate:

try session.setCategory(.playAndRecord, mode: .default)
try session.setActive(true)
print("Hardware sample rate:", session.sampleRate)

I consistently get: `Hardware sample rate: 48000.0

My questions are:

Is the iPhone mic actually capturing at 8 kHz, or is it recording at 48 kHz and then downsampling to 8 kHz internally?

Is there any way to force the hardware to record natively at 8 kHz?

If not, what’s the recommended approach for telephony-quality audio (true 8 kHz) on iOS devices?

Thanks in advance for your guidance!

Is the iPhone mic actually capturing at 8 kHz, or is it recording at 48 kHz and then downsampling to 8 kHz internally?

the latter. Your own investigation indicates this. The microphone doesn't record, it provides samples. The AVAudioRecorder records, you gave it the settings to use.

Is there any way to force the hardware to record natively at 8 kHz?

Have you tried setPreferredSampleRate? The docs say it is hardware dependent, the microphone might provide samples at a single fixed, or a few fixed rates.

If not, what’s the recommended approach for telephony-quality audio (true 8 kHz) on iOS devices?

Well, 8kHz 16-bit recordings from a modern iPhone microphone probably yields better than telephone quality. What are you actually trying to achieve? "Sounds like an old analog telephone" is probably a job for a narrow bandwidth filter (300 to 3.5kHz), the injection of noise at about 45 dB below the maximum amplitude, and some distortion and clipping.

See https://developer.apple.com/documentation/avfoundation/creating_custom_audio_effects

Why does AVAudioRecorder show 8 kHz when iPhone hardware is 48 kHz?
 
 
Q