1

I am using the following code to get the audio sample of the 44100 sample rate from the iPhone 11. iPhone 11 has a 48000 sample rate by default.

let audioEngine = AVAudioEngine()
    let inputNode = audioEngine.inputNode
    let main = audioEngine.mainMixerNode
    let inputFormat = inputNode.inputFormat(forBus: 0)
    let outputFormat = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)
    audioEngine.attach(downMixer)
    audioEngine.connect(inputNode, to: downMixer, format: inputFormat)
    audioEngine.connect(downMixer, to: main, format: outputFormat)
    downMixer.installTap(onBus: 0, bufferSize: 2048, format: outputFormat) { (buffer, time) -> Void in
        print(buffer)
    }

I am getting null audio data.

Raj Aggrawal
  • 761
  • 1
  • 6
  • 21

1 Answers1

0

You can use Audio Converter Services for converting 48 K Hz to 44.1 K Hz sampling frequency. As all the sampling frequency is not supported by the iOS/iphone platform.

https://developer.apple.com/documentation/audiotoolbox/audio_converter_services

mail2subhajit
  • 1,106
  • 5
  • 16
  • any source for knowing which device / iOS version supports which SR? – N4ppeL Feb 15 '22 at 16:05
  • Earlier there was a API for this, but now it is deprecated - you can check in apple forum. https://developer.apple.com/documentation/avfaudio/avaudiosession/1616494-currenthardwaresamplerate – mail2subhajit Feb 16 '22 at 12:43