3

I'm working with the new Apple Speech library and I can't find a command to flip the isFinal bool and end the transcription after a few seconds of silence. Does anyone know how to end the task after a bit of silence?

Here is the code which I receive speech transcription results.

    recognitionRequest.shouldReportPartialResults = true

    speechRecogTask = speechRecognizer.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
        var isFinal = false
        if result != nil {

            self.textField.text = result?.bestTranscription.formattedString
            isFinal = (result?.isFinal)!
        }

        if error != nil || isFinal {
            self.audioEngine.stop()
            inputNode.removeTap(onBus: 0)

            self.speechRecogRequest = nil
            self.speechRecogTask = nil
        }
    })

Any ideas?

Patrick
  • 66
  • 1
  • 6

2 Answers2

3

Your best bet would be to use a timer to detect the interval when the last delegate was invoked. Have a look at this library which is using a NSTimer

Devang
  • 320
  • 3
  • 12
0
if let result = result {
                
  if (isFinal == true) {
    self.speechRecogTask?.finish()
  }

}
Christos
  • 1
  • 5