title: Is it possible to use speech recognition in a SpriteKit app using swift?
body: <p>I am using SpriteKit to build an app.  The other functionality of the Scene is all done through SpriteKit.  I want to add speech recognition to the scene so that when the user touches the microphone button node, the words they say are matched against the correct word they needed to say to move on.  Is this possible on SpriteKit?  The code below is the function I am using but it is not causing anything to happen.</p>
  
  <pre><code>func recordAndRecognizeSpeech() {
      let node = audioEngine.inputNode
      let recordingFormat = node.outputFormat(forBus: 0)
      node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { buffer, _ in
          self.request.append(buffer)
      }
      audioEngine.prepare()
      do {
          try audioEngine.start()
      } catch {
          self.sendAlert(message: "There has been an audio engine error.")
          return print(error)
      }
      guard let myRecognizer = SFSpeechRecognizer() else {
          self.sendAlert(message: "Speech recognition is not supported for your current locale.")
          return
      }
      if !myRecognizer.isAvailable {
          self.sendAlert(message: "Speech recognition is not currently available. Check back at a later time.")
          // Recognizer is not available right now
          return
      }
      recognitionTask = speechRecognizer?.recognitionTask(with: request, resultHandler: { result, error in
          if let result = result {
  
              let bestString = result.bestTranscription.formattedString
              self.labelNode.text = bestString
  
              var lastString: String = ""
              for segment in result.bestTranscription.segments {
                  let indexTo = bestString.index(bestString.startIndex, offsetBy: segment.substringRange.location)
                  lastString = bestString.substring(from: indexTo)
              }
              self.checkPhrase(resultString: lastString)
          } else if let error = error {
              self.sendAlert(message: "There has been a speech recognition error.")
              print(error)
          }
      })
  }
  </code></pre>
  
  <p>Below is the code I am using for when the mic node gets touched and nothing happens when I run it:</p>
  
  <pre><code>override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
      guard let touch = touches.first else { return }
      let location = touch.location(in: self)
  
  
      if micButton.contains(location) {
          if isRecording == true {
              audioEngine.stop()
              recognitionTask?.cancel()
              isRecording = false
          } else {
              self.recordAndRecognizeSpeech()
              isRecording = true
          }
  
  
      }
  </code></pre>