AVFoundation error with Speech API

Sometimes, when I am trying to setup the new Speech API to recognize a live audio stream (from microphone as demo'd in the official WWDC video), I sometimes get the following error (on an actual device). It usually happens after a recognition request has already been called.

Recognition error: Optional(Error Domain=kAFAssistantErrorDomain Code=216 "(null)")


Let's assume that I have user permission and that the speech recognizer is available (both are true at the time of the crash). The method I invoke is:


private func listen() throws {
    if let recognitionTask = self.recognitionTask {
      recognitionTask.cancel()
      self.recognitionTask = nil
    }
    self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
    guard let recognitionRequest = self.recognitionRequest else { fatalError("Unable to created a SFSpeechAudioBufferRecognitionRequest object") }
    guard let inputNode = audioEngine.inputNode else { fatalError("Audio engine has no input node") }
    recognitionRequest.shouldReportPartialResults = true

    self.recognitionTask = speechRecognizer?.recognitionTaskWithRequest(recognitionRequest, resultHandler: { (result, error) in
        print("Error: " + String(error)) // THIS IS THE ERROR

        // Code here in which I look for certain phrases - irrelevant
    })

    let recordingFormat = inputNode.outputFormatForBus(0)
    inputNode.installTapOnBus(0, bufferSize: 2048, format: recordingFormat, block: { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
      recognitionRequest.appendAudioPCMBuffer(buffer)
    })

    self.audioEngine.prepare()
    try self.audioEngine.start()

}

The error is the one in the -recognitionTaskWithRequest completion handler. Most of these variables are declared or defined outside of the method body:

  private let audioEngine = AVAudioEngine()
  private var speechRecognizer: SFSpeechRecognizer?
  private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?
  private var recognitionTask: SFSpeechRecognitionTask?


I couldn't find an AVFoundation error with the code "216". Any thoughts?

I got the same error too and don't have much clue. Really needs some Apple engineers to have a look.

Any update on how to solve this?

Apple - can you tell us where to find the meaning of these error codes?

What does the code mean? Did you find anything guys?

It looks like an error generated by Nuance, the backend engine that is processing the raw audio. Their error description indicates the following:


216

INVALID_ACTION_PARAMS

Invalid action setup data were detected. The action cannot be executed. Contact Nuance Support.


Unfortunately, it's not very helpful. In my case, everything was working fine one moment, then stopped working. So this could be a sporatic issue between Apple and Nuance.

AVFoundation error with Speech API
 
 
Q