SFSpeechRecognizer kAFAssistantErrorDomain Code=203 "Retry"
Asked Answered
A

1

7

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()
 }
}
Auroreaurous answered 8/1, 2018 at 3:35 Comment(0)
L
7

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.

Lubbock answered 9/11, 2018 at 22:44 Comment(6)
Why was "finish it" struck out? I get this error even though I'm finishing the request.Environment
My bad. The first answer I wrote includes code for cancel or finish the recognition task, but the original code had already a function with the finish(), so I edited it to only include the cancel(). Maybe I should rewrite it inside parenthesis. Even worse, I realize that my answer is bad, I mixed up variables and methods. I do not know what I was thinking. I am going to correct it.Callboy
I've seen error 1700 on a legal phone. Not sure what causes it though.Dib
This answer is a guess or is there any official documentation that backs it?Perlie
Pure guess. But I do not know if there is an official documentation, at least I have not found it.Callboy
It only happened to me in my jailbroken iPhones, but I remember reading that other people have the same error without a jailbreak, so I do not know yet what that error means :(Callboy

© 2022 - 2024 — McMap. All rights reserved.