【发布时间】:2020-09-04 13:25:44
【问题描述】:
我有一个奇怪的错误,它只发生在 iPad 物理设备、iPhone 物理设备和所有 iPad 模拟器上都运行良好,但在 iPad 物理设备上我得到 Error Domain=kAFAssistantErrorDomain Code=1700。这怎么会发生?
我的 SFSpeechRecognizer 代码:
func requestTranscribePermissions() {
SFSpeechRecognizer.requestAuthorization { [unowned self] authStatus in
DispatchQueue.main.async {
if authStatus == .authorized {
print("Good to go!")
} else {
print("Transcription permission was declined.")
}
}
}
}
func convertAudioToText() {
if let file = audio {
print(file)
let recognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
let request = SFSpeechURLRecognitionRequest(url: file)
request.shouldReportPartialResults = false
if (recognizer?.isAvailable)! {
recognizer?.recognitionTask(with: request) { result, error in
guard error == nil else { print("Error: \(error!)"); return }
guard let result = result else { print("No result!"); return }
self.text = result.bestTranscription.formattedString
self.performSegue(withIdentifier: "Convert", sender: nil)
print(result.bestTranscription.formattedString)
}
} else {
print("Device doesn't support speech recognition")
}
} else {
let alert = UIAlertController(title: "There's no audio", message: "No audio recorded", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
self.present(alert, animated: true, completion: nil)
}
}
我只在 iPad 物理设备上获得:
[Utility] +[AFAggregator logDictationFailedWithError:] 错误域=kAFAssistantErrorDomain Code=1700 "(null)" 错误:错误域=kAFAssistantErrorDomain Code=1700 "(null)"
【问题讨论】:
标签: ios swift ipad speech-recognition