我正在我的应用程序中使用语音框架实现语音到文本。 如果textview中已经有一些文本,我怎么能用语音识别器附加它?
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
var isFinal = false
if let result = result {
self.dataTextView.text = self.dataTextView.text.appending(result.bestTranscription.formattedString)
isFinal = result.isFinal
}
if error != nil || isFinal {
//stop recognising speech
self.audioEngine.stop()
inputNode.removeTap(onBus: 0)
}
})
假设,我通过键盘“测试数据”将文本添加到textview。现在使用语音识别器我说“这是新数据”,我期待结果是测试数据这是新数据“。结果如同在aattchment中
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
if let result = result {
let bestString = result.bestTranscription.formattedString
self.dataTextView.text = bestString
}
}
像这样你应该能够将它添加到你的textview