Swift – Recognize spoken text using Siri

A draft of SpeechManager.swift, that recognize the spoken text using Siri.

It use the Apple Speech framework (https://developer.apple.com/documentation/speech):

Perform speech recognition on live or prerecorded audio, receive transcriptions, alternative interpretations, and confidence levels of the results.


How to use

Import the SpeechManager.swift into your project and call it from your controller:

class ViewController: UIViewController {

    // the speech manager
    var speechManager: SpeechManager?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // init with language
        speechManager = SpeechManager(delegate: self, language: "it-IT")
    }
}

// SpeechManagerProtocol, called on text recognized
extension ViewController: SpeechManagerProtocol {
    func didTextRecognized(text: String) {
        print( text )
    }
}

Full SpeechManager here:


Enjoy with Siri!

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.