语音识别在iOS上出错

前端之家收集整理的这篇文章主要介绍了语音识别在iOS上出错前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究iOS上的语音识别,但每次调用方法[_recognitionRequest endAudio]时,它总是在recognitionTaskWithRequest中出错:消息在底部.
  1. -(void) stopRecording {
  2. if (_disableSpeechSW == YES) {
  3. return;
  4. }
  5. if (_isAuthorization == NO) {
  6. return;
  7. }
  8.  
  9. NSLog(@"stopRecording");
  10.  
  11. if ([_audioEngine isRunning]) {
  12. [_audioEngine stop];
  13. [_recognitionRequest endAudio];
  14. }

}

  1. -(void) startRecording {
  2. ..........
  3. [_speechRecognizer recognitionTaskWithRequest:_recognitionRequest
  4. resultHandler:^(SFSpeechRecognitionResult *result,NSError *error){
  5. if (error != nil ) {
  6. NSLog(@"%@",[error description]);
  7. }
  8. else {
  9. ..........
  10. }
  11. }];}

[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

猜你在找的iOS相关文章