我的演讲识别功能似乎没有被调用。我在文档中找不到有关调用此函数的任何内容。 知道我可能做错了什么吗?提前谢谢。
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")
}
}
}
答案 0 :(得分:3)
将NSSpeechRecognizerDelegate
设置为self
:
SR.delegate = self