7

I try using speech recognition as below

    let urlpath = Bundle.main().pathForResource("myvoice2", ofType: "m4a")
    let url:URL = URL.init(fileURLWithPath: urlpath!)

    let recognizer = SFSpeechRecognizer()
    let request = SFSpeechURLRecognitionRequest(url: url)
    recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
        print (result?.bestTranscription.formattedString)

    })

The result is nil, I debug and see the error as below

Error Domain=kAFAssistantErrorDomain Code=1101 "(null)"

Do you have any idea?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dong Duong
  • 73
  • 1
  • 1
  • 4

1 Answers1

13

I have the same error, but identical code worked fine on device. So, install iOS 10 beta on a physical device and run your code. Something like this ought to do the trick:

SFSpeechRecognizer.requestAuthorization { authStatus in
    if authStatus == SFSpeechRecognizerAuthorizationStatus.authorized {
        if let path = Bundle.main().urlForResource("test", withExtension: "m4a") {
            let recognizer = SFSpeechRecognizer()
            let request = SFSpeechURLRecognitionRequest(url: path)
            recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
                if let error = error {
                    print("There was an error: \(error)")
                } else {
                    print (result?.bestTranscription.formattedString)
                }
            })
        }
    }
}

I wrote about this in more detail here.

TwoStraws
  • 12,862
  • 3
  • 57
  • 71
  • 2
    That's right, thanks @TwoStraws. The issue occurs on Simulator, It worked on real device. – Dong Duong Jun 15 '16 at 01:07
  • 3
    I've been testing on real device and the issue is still there. It's like the App is running for a while but it stopped with the same error: Error Domain=kAFAssistantErrorDomain Code=203 "Timeout" UserInfo={NSLocalizedDescription=Timeout, NSUnderlyingError=0x17004ff30 {Error Domain=SiriSpeechErrorDomain Code=100 "(null)"}} Any thought about this? Thanks – Va Visal Sep 19 '16 at 05:02
  • 3
    @VaVisal the timeout error is caused by never calling endAudio method of the SFSpeechURLRecognitionRequest instance. – Valent Richie Oct 04 '16 at 01:52
  • Anyone fix Error Domain=kAFAssistantErrorDomain Code=203 ? – SaRaVaNaN DM Apr 28 '17 at 06:25