我想创建两个可以并行运行的SpeechRecognizer实例,这是代码
func Selection_TButton(url : URL) {
guard let newrecognizer = SFSpeechRecognizer() else {
print("No Speech Recognizer avaiable ")
return
}
if !newrecognizer.isAvailable {
print("recognizer is not availble")
return
}
let recognitionRequest = SFSpeechURLRecognitionRequest(
url: url)
newrecognizer.recognitionTask(with: recognitionRequest) { result, error in
if (error != nil) {
print("fails with error: \(error!.localizedDescription)")
}
if let result = result {
self.TextView.text = result.bestTranscription.formattedString
print(result.isFinal)
if result.isFinal == true {
let formattedString : String?
formattedString = result.bestTranscription.formattedString
}
}
这就是我要通过传递URL路径调用此函数的方式
self.Selection_TButton(url: finalPath1)
self.Selection_TButton(url: finalPath2)
我该如何完成?
我尝试过,但它会触发一个SpeechRecognizer实例,而使另一个实例失败并显示错误代码
error domain = kafassistanterrordomain code = 209
对此有何建议?