Speech Recognition got an error on iOS

user1028886 picture user1028886 · Oct 8, 2016 · Viewed 9.2k times · Source

I'm studying the Speech Recognition on the iOS, but Every time I call the method [_recognitionRequest endAudio] , it always got an error in recognitionTaskWithRequest: the message is in the bottom.

-(void) stopRecording {
if (_disableSpeechSW == YES) {
    return;
}
if (_isAuthorization == NO) {
    return;
}

NSLog(@"stopRecording");

if ([_audioEngine isRunning]) {
    [_audioEngine stop];
    [_recognitionRequest endAudio];
}

}

-(void) startRecording {
..........
[_speechRecognizer recognitionTaskWithRequest:_recognitionRequest
                   resultHandler:^(SFSpeechRecognitionResult *result,NSError *error){
  if (error != nil ) {
     NSLog(@"%@",[error description]);
  }
  else {
   ..........
  }
}];}

[Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=203 "Retry" UserInfo={NSLocalizedDescription=Retry, NSUnderlyingError=0x17424c690 {Error Domain=SiriSpeechErrorDomain Code=1 "(null)"}}

Answer

Sandip Patel - SM picture Sandip Patel - SM · Jun 9, 2017

For more clarification about siri speech limitation see this post: Speech Recognition Limits for iOS 10

Use my function below to stop speech recognization. Hope its works.

-(void)stopRecording{

    dispatch_async(dispatch_get_main_queue(), ^{

        if(audioEngine.isRunning){
            [inputNode removeTapOnBus:0];
            [inputNode reset];
            [audioEngine stop];
            [recognitionRequest endAudio];
            [recognitionTask cancel];
            recognitionTask = nil;
            recognitionRequest = nil;
        }
    });
}