iOS speech kit,the SFSpeechRecognizer and AVAudioEngine work together to speech recognition, crash sometime when the mic is used by other progress.
self.audioEngine = [[AVAudioEngine alloc] init];
AVAudioInputNode *inputNode = self.audioEngine.inputNode;
AVAudioFormat *nativeAudioFormat = [inputNode outputFormatForBus:0];
__weak typeof(self)weakSelf = self;
[inputNode installTapOnBus:0 bufferSize:1024 format:nativeAudioFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[weakSelf.recognitionRequest appendAudioPCMBuffer:buffer];
}];
[self.audioEngine prepare];
[self.audioEngine startAndReturnError:&error];
Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'