代码如下
- (void)startAudioEngine { NSError *error = nil; if (!self.audioEngine.isRunning) { self.audioEngine = [[AVAudioEngine alloc] init]; AVAudioInputNode *inputNode = self.audioEngine.inputNode; AVAudioFormat *nativeAudioFormat = [inputNode inputFormatForBus: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]; if (error) { [self stop]; [self onError:[NSError errorWithDomain:@"startAudioEngine error" code:0 userInfo:nil]]; } else { [self activeStatusChanged:MMSpeechRecognizerActiveStatusStared]; } } else { [self stop]; [NSError errorWithDomain:@"The audio engine is runing" code:0 userInfo:nil]; } }
iOS 14 在 self.audioEngine.inputNode时crash.
日志如下:
[plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000032144c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46 HALB_IOBufferManager_Client::GetIOBuffer: the stream index is out of range HALB_IOBufferManager_Client::GetIOBuffer: the stream index is out of range [aqme] 255: AQDefaultDevice (1): output stream 0: null buffer [aqme] 1778: EXCEPTION thrown (-50): error != 0 Initialize: Mach message timeout. Apparently deadlocked. Aborting now. CoreSimulator 725.10 - Device: iPhone 11 (003A9CF3-FDD7-4C44-8607-CAB3FDBB904B) - Runtime: iOS 14.0 (18A5301v) - DeviceType: iPhone 11
解决方法
iOS系统的错误.
这个问题Apple已经修复. 出现在Xcode Version 12.0 beta (12A6159). Version 12.0 beta 2 (12A6163b) 已经修复.