iOS 10.0语音识别错误kAFAssistantErrorDomain

前端之家收集整理的这篇文章主要介绍了iOS 10.0语音识别错误kAFAssistantErrorDomain前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试使用语音识别如下
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)

    })

结果是nil,我调试并看到如下错误

错误域= kAFAssistantErrorDomain代码= 1101“(null)”

你有什么主意吗?

解决方法

我有相同的错误,但相同的代码在设备上工作正常.因此,在物理设备上安装iOS 10 beta并运行您的代码.像这样的东西应该做的伎俩:
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,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.

原文链接:https://www.f2er.com/iOS/332296.html

猜你在找的iOS相关文章