Building a very simple voice-to-text app, which I got from an online demo.
What I can't seem to find is how to reset the response back to nil. This demo just keeps transcribing from the very beginning till it finally stalls.
While I don't know how if the stall is related to my question, I still need to find out how to code "Ok, got the first 100 words. Reset response text to nil. Continue."
func startSpeechRecognition(){
let node = audioEngine.inputNode
let recordingFormat = node.outputFormat(forBus: 0)
node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat, block: { (buffer, _) in self.request.append(buffer)})
audioEngine.prepare()
do {
try audioEngine.start()
} catch let error {
alertView(message: "audioEngine start error")
}
guard let myRecognition = SFSpeechRecognizer() else {
self.alertView(message: "Recognition is not on your phone")
return
}
if !myRecognition.isAvailable {
self.alertView(message: "recognition is not available right now")
}
task = speechRecognizer?.recognitionTask(with: request, resultHandler: { (response, error) in
guard let response = response else {
if error != nil {
self.alertView(message: error!.localizedDescription.debugDescription)
} else {
self.alertView(message: "Unknow error in creating task")
}
return
}
let message = response.bestTranscription.formattedString
self.label.text = message
})
}