【问题标题】:Swift: how to call NSSpeechRecognizer funcSwift:如何调用 NSSpeechRecognizer 函数
【发布时间】:2014-12-17 21:22:09
【问题描述】:

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

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

【问题讨论】:

    标签: macos swift speech-recognition


    【解决方案1】:

    NSSpeechRecognizerDelegate 设置为self

    SR.delegate = self
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      相关资源
      最近更新 更多