繁体   English   中英

Swift:如何调用NSSpeechRecognizer func

[英]Swift: how to call NSSpeechRecognizer func

我的speechRecognizer func似乎没有被调用。 我在文档中找不到有关调用此函数的任何内容。 知道我可能做错了什么吗? 提前致谢。

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")
        }
}
}

NSSpeechRecognizerDelegate设置为self

SR.delegate = self

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM