Simple Voice Recognition Swift?

Junaid picture Junaid · Apr 10, 2015 · Viewed 18.4k times · Source

In my app when the user says a certain word or words the app will answer by reading out a sentence which is set in app. What is the simplest way of doing this?

I'm using the latest version of Xcode (Its for my WWDC 2015 scholarship app)

Answer

fpg1503 picture fpg1503 · Jun 22, 2016

As of iOS 10 you can use Speech.framework:

import Speech

let recognizer = SFSpeechRecognizer()
let request = SFSpeechURLRecognitionRequest(url: audioFileURL)
recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
     print (result?.bestTranscription.formattedString)
})