【发布时间】: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