Audiokit: AKMicrophone is crashing with Fatal Exception: com.apple.coreaudio.avfaudio required condition is false: IsFormatSampleRateAndChannelCountValid

Created on 4 May 2019  路  12Comments  路  Source: AudioKit/AudioKit

This happens in the wild across all iOS device and I was never able to reproduce it on any of my devices.

I saw there was an update with optional initializer for AKMicrophone, but it still fails for me with a fatal error at the following line in the init?:

AudioKit.engine.connect(AudioKit.engine.inputNode, to: self.avAudioNode, format: format)

If there is no way to avoid this is there at least a way to handle this gracefully?

Fatal Exception: com.apple.coreaudio.avfaudio
0 CoreFoundation 0x19e198518 __exceptionPreprocess
1 libobjc.A.dylib 0x19d3739f8 objc_exception_throw
2 CoreFoundation 0x19e0b2148 +[_CFXNotificationTokenRegistration keyCallbacks]
3 AVFAudio 0x1a3f59438 AVAE_RaiseException(NSString, ...)
4 AVFAudio 0x1a3f58a70 _AVAE_Check(char const
, int, char const, char const, bool)
5 AVFAudio 0x1a3ff9268 AVAudioIONodeImpl::SetOutputFormat(unsigned long, AVAudioFormat)
6 AVFAudio 0x1a3f893c8 AVAudioEngineGraph::_Connect(AVAudioNodeImplBase
, AVAudioNodeImplBase, unsigned int, unsigned int, AVAudioFormat)
7 AVFAudio 0x1a4000e9c AVAudioEngineImpl::Connect(AVAudioNode, AVAudioNode, unsigned long, unsigned long, AVAudioFormat*)
8 AVFAudio 0x1a4000f24 -[AVAudioEngine connect:to:format:]
9 PerfectEar 0x104b8e7d8 AKMicrophone.init(with:) (AKMicrophone.swift:64)
10 PerfectEar 0x1048bf3f8 PitchTrackerNode.setup() (PitchTrackerNode.swift:41)

Most helpful comment

@aure I have the same issue, when make a phone call and I start my app which initialize AKMicrophone, it crashes. Any suggestion to avoid the situation ? thanks.

All 12 comments

Update. Actually, my mistake, after updating to latest changes, the exception code has indeed changed to "IsFormatSampleRateAndChannelCountValid(hwFormat)".

So I am not able to reproduce this. Can you supply a sample project that causes this issue so I can test? I'll reopen the issue with new info.

It's very simple to reproduce this. start a call to someone. then run app with code 'let mic = AKMicrophone()'.

@aure I can confirm that I can reproduce this using the method @ghubaddole described.

@aure I have the same issue, when make a phone call and I start my app which initialize AKMicrophone, it crashes. Any suggestion to avoid the situation ? thanks.

I have the same issue, I start my app which initialize AKMicrophone, it crashes. Any suggestion to avoid the situation ? thanks you very much

I can also confirm this issue occurs if a microphone is instantiated while on a phone call. I've tried to catch the error but have been unsuccessful so far.

@aure - Can we reopen this issue for visibility?

I'm able to prevent the crash and successfully instantiate a microphone while on a phone call by explicitly setting the AVAudioSession category and active state immediately before setting the sampleRate of AKSettings and instantiating an AKMicrophone

Here's what it looks like:

let audioSession = AVAudioSession.sharedInstance()
do {
     try audioSession.setCategory(.playAndRecord)
     try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
} catch {
     print("setting category or active state failed")
}

let inputAudioFormat = AudioKit.engine.inputNode.inputFormat(forBus: 0)
AKSettings.sampleRate = inputAudioFormat.sampleRate

self.mic = AKMicrophone()

Also, I have AKSettings.disableAVAudioSessionCategoryManagement set to false.

AKMicrophone is being removed from AudioKit due to issues like this. The new one is more stable and simple.

What is the alternative for AKMicrophone in v5?

engine.input

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crashingbooth picture crashingbooth  路  4Comments

mahal picture mahal  路  7Comments

adamjsutcliffe picture adamjsutcliffe  路  10Comments

trevor-sonic picture trevor-sonic  路  6Comments

vojtabohm picture vojtabohm  路  8Comments