Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudioEngine causes AUGraphParser::InitializeActiveNodesInInputChain error on iOS 13

I am using SFSpeechRecognizer and noticed this error showing up on iOS >= 13.

This is my code for starting recognition process:

- (void)startRecording:(BOOL)collectPartialResults {    
    NSError *error;
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
    [audioSession setMode:AVAudioSessionModeMeasurement error:&error];
    [audioSession setActive:YES error:&error];

    AVAudioInputNode *inputNode = _audioEngine.inputNode;

    _recognitionRequest = [SFSpeechAudioBufferRecognitionRequest new];
    _recognitionRequest.shouldReportPartialResults = collectPartialResults;

    _recognitionTask = [_internalRecognizer recognitionTaskWithRequest:_recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
       // ...
    }];

    AVAudioFormat *format = [inputNode outputFormatForBus:0];

    @try {
        [inputNode installTapOnBus:0 bufferSize:1024 format:format block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
            [_recognitionRequest appendAudioPCMBuffer:buffer];
        }];
    }
    @catch (NSException *exception) {
        NSLog(@"%@", exception.userInfo);
        [self sendStartRecordingErrorMessage:[NSString stringWithFormat:@"%@", exception.userInfo]];
        return;
    }

    NSError *startError;
    [_audioEngine startAndReturnError:&startError];

    if (startError != nil) {
        [self sendStartRecordingErrorMessage:[NSString stringWithFormat:@"%@", startError.userInfo]];
    }
}

This works for one or two times, but eventually leads to this error:

AVAEInternal.h:109   [AVAudioEngineGraph.mm:1397:Initialize: (err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph, *GetInputNode())): error -10851

caused by this line: [_audioEngine startAndReturnError:&startError];

I have no idea what does this error mean. My code is almost the same as official example.

I've tried several things such as:

  • using outputFormatForBus instead of inputFormatForBus for installTapOnBus,
  • using different audioSession mode (AVAudioSessionModeVoicePrompt),
  • calling [audioEngine reset] before starting recoding process
like image 501
Piotr Avatar asked Oct 27 '25 09:10

Piotr


1 Answers

I had the same issue. For me the solution was to use a new AVAudioEngine for each recording.

In your example:

- (void)startRecording:(BOOL)collectPartialResults {
  _audioEngine = [[AVAudioEngine alloc] init];

  // ...
}
like image 142
lassej Avatar answered Oct 29 '25 00:10

lassej