10

I am using AVAudioSession and AVAudioInputNode to record voice in iOS.

To initialise it I was using the following settings, which was working fine:

[AVFormatIDKey: kAudioFormatLinearPCM, AVLinearPCMBitDepthKey: 16, AVLinearPCMIsFloatKey: true, AVSampleRateKey: Float64(8000), AVNumberOfChannelsKey: 1] as [String : Any]

Now, in my new iPhone 11 Pro, with this code I get a crash with this error: required condition is false: format.sampleRate == hwFormat.sampleRate

The way to avoid it is to set the sample rate from the AVSession:

[AVFormatIDKey: kAudioFormatLinearPCM, AVLinearPCMBitDepthKey: 16, AVLinearPCMIsFloatKey: true, AVSampleRateKey: AVAudioSession.sharedInstance().sampleRate, AVNumberOfChannelsKey: 1] as [String : Any]

That code works on my iPhone 11 Pro, but now it crashes on the other devices.

Any idea how to fix it for everyone? Why is this happening? What changed?

Thank you!

Joan Cardona
  • 3,463
  • 2
  • 25
  • 43

0 Answers0