Swift: how to call NSSpeechRecognizer function

My speech reconnaissance function doesn't seem to be called. I couldn't find anything in the documentation about calling this function. Any idea what I might be doing wrong? Thanks in advance.

class ViewController: NSViewController, NSSpeechRecognizerDelegate {

let SR:NSSpeechRecognizer = NSSpeechRecognizer()
var commands = ["word","hello"]

override func viewDidLoad() {
    super.viewDidLoad()

    SR.commands = commands
}

override var representedObject: AnyObject? {
    didSet {
    // Update the view, if already loaded.
    }
}

@IBAction func Listen(sender: AnyObject) {
    SR.startListening(); print("listening")
}

@IBAction func Stop(sender: AnyObject) {
    SR.stopListening()
}

func speechRecognizer(sender: NSSpeechRecognizer,
    didRecognizeCommand command: AnyObject?){

        if (command as String == "word")
        {
            println("case word")
        }
        else if (command as String == "happy")
        {
            println("case happy")
        }
}
}

      

+3


source to share


1 answer


Install NSSpeechRecognizerDelegate

on self

:



SR.delegate = self

      

+3


source







All Articles