SFSpeechRecognizer kAFAssistantErrorDomain Code=203 “Retry”

左心房为你撑大大i 提交于 2019-12-07 11:14:21

问题


I use SFSpeechRecognizer, basically to work.

1.But sometimes the following error occurs. And mostly before I did not execute avStop().

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

2.And completely unable to work in the background, will produce the following error.

[Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=1700 "(null)"

class MySpeech:NSObject{
 private var iosRecognizer: SFSpeechRecognizer?
 private var iosRequest: SFSpeechAudioBufferRecognitionRequest?
 private var iosTask: SFSpeechRecognitionTask?
 private let iosAVE = AVAudioEngine()
 private let avSession = AVAudioSession.sharedInstance()

 func avINIT(){
    try? avSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.allowBluetooth])
    try? avSession.setMode(AVAudioSessionModeMeasurement)
    try? avSession.setActive(true, with: .notifyOthersOnDeactivation)
 }
 func switchHFP(){
    do{
        //try avSession.setActive(false)
        try avSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.allowBluetooth])
        try avSession.setActive(true, with: .notifyOthersOnDeactivation)
    } catch {
        debugPrint("HFP error: \(error.localizedDescription)")
    }
}
 func avStart(_ sLNG:NSString){
        if let iosTask = iosTask {
            iosTask.cancel()
            self.iosTask = nil
        }
        iosRecognizer=SFSpeechRecognizer(locale: Locale(identifier:sLNG as String))!
        iosRequest = SFSpeechAudioBufferRecognitionRequest()

        guard let inputNode = iosAVE.inputNode else { fatalError("Audio engine has no input node") }

        guard let recognitionRequest = iosRequest else { fatalError("Unable to created a SFSpeechAudioBufferRecognitionRequest object") }

        recognitionRequest.shouldReportPartialResults = false

        iosTask = iosRecognizer?.recognitionTask(with: recognitionRequest) { result, error in
            if let result = result {
                if result.isFinal {
                    self.iosAVE.stop()
                    inputNode.removeTap(onBus: 0)
                    self.iosRequest = nil
                    self.iosTask = nil

                    self.textView.text = result.bestTranscription.formattedString
                }
            }else if error != nil{
                self.iosAVE.stop()
                inputNode.removeTap(onBus: 0)
                self.iosRequest = nil
                self.iosTask = nil

                self.textView.text = error?.localizedDescription ?? "(NULL)"
            }
        }

        let recordingFormat = iosAVE.inputNode?.outputFormat(forBus: 0)

        inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
            self.iosRequest?.append(buffer)
        }

        iosAVE.prepare()
        do{
            try iosAVE.start()
        } catch { print("Error: Start Record") }
    }
 }

 func avStop(){
        iosTask?.finish()
        iosRequest?.endAudio()
 }
}

回答1:


The kAFAssistantErrorDomain 203 is when the SFSpeechRecognizer could not detect any result when you finish or cancel a SFSpeechRecognitionTask. Maybe you are calling avStart(_) twice, causing to cancel the first task with no results.

About the kAFAssistantErrorDomain 1700 until now I do not know what cause the problem. But only happened to me with a jailbroken iPhone.



来源:https://stackoverflow.com/questions/48143918/sfspeechrecognizer-kafassistanterrordomain-code-203-retry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!