0

I'm implementing voice to text using speech framework in my app.
If there was already some text in the textview, how can I append it with speech recognizer?

    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)
        }
    })

Suppose that, I added text to textview via keyboard "Test data". now using speech recognizer I said "This is new data", I'm expecting result to be Test data This is new data". Result is as in aattchment

enter image description here

Neha Vipin
  • 688
  • 6
  • 17

1 Answers1

0
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
    if let result = result {
        let bestString = result.bestTranscription.formattedString
        self.dataTextView.text = bestString
    }
}

Like this you should be able to add it to your textview

  • Suppose that, I added text to textview via keyboard "Test data". now using speech recognizer I said "This is new data", I'm expecting result to be Test data This is new data". The same screenshot added in question is the result I'm getting even after using like this – Neha Vipin Dec 05 '18 at 08:54
  • When you say "This is new data" the speech recognize a lot of "This" and it wrote them down, you can use a control after you pick the bestString; you can see if it's already in your textField and if it is do not append anything – Francesco Destino Dec 05 '18 at 09:00