我正在研究iOS上的语音识别,但每次调用方法[_recognitionRequest endAudio]时,它总是在recognitionTaskWithRequest中出错:消息在底部.
-(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)”}}
解决方法
我想通了“endAudio”不允许从RecognitionTaskWithRequest块外面调用,如果你直接调用方法“[self stopRecording]”那么块会立即响应错误“kAFAssistantErrorDomain Code = 203”.
这是我的代码中使用stopRecord的4部分
1和2很好
3和4错误
1.from block→detecedVoice→withVoiceControl→stopRecord→ok
2.from block error→stopRecord→startRecord→ok
3.button tap→stopRecord→kAFAssistantErrorDomain Code = 203
4.timer 40s→stopRecord→startRecord→kAFAssistantErrorDomain Code = 203