如何创建两个可以并行/并行运行的SpeechRecognizer实例?

时间:2019-07-18 04:45:28

标签: swift speech-recognition

我想创建两个可以并行运行的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

对此有何建议?

0 个答案:

没有答案