iOS 10.0 语音识别错误 kAFAssistantErrorDomain
iOS 10.0 Speech Recognition Error 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,我debug看到错误如下
Error Domain=kAFAssistantErrorDomain Code=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, resultHandler: { (result, error) in
if let error = error {
print("There was an error: \(error)")
} else {
print (result?.bestTranscription.formattedString)
}
})
}
}
}
我尝试如下使用语音识别
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,我debug看到错误如下
Error Domain=kAFAssistantErrorDomain Code=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, resultHandler: { (result, error) in
if let error = error {
print("There was an error: \(error)")
} else {
print (result?.bestTranscription.formattedString)
}
})
}
}
}