2012-07-14 120 views
0

我一直在用各种测试程序进行一段时间的语音识别,这一切都很好。然而,我已经尝试将它实现到我的OpenGL项目中,并且现在没有调用'Recognized'函数。C#语音识别(System.Speech.Recognition)问题

在Windows语音识别的事情(说“试着说'开始听''的事很多),加载的词出现,当我说他们,所以我假设它正确地检测词,只是由于某种原因不能触发事件。

这是我一直在使用的代码。所有你真正需要知道的(除了在代码中显示的),AddCommands被调用到其他地方,添加一些我已经测试过的单词,并且在加载表单时调用“Initiate” 。

public class SpeechControls 
{ 
    public static SpeechRecognizer sRecognizer; 

    private static Dictionary<string, IVoiceControlable> controllers = new Dictionary<string, IVoiceControlable>(); 

    public static void Initiate() 
    { 
     sRecognizer = new SpeechRecognizer(); 
     sRecognizer.Enabled = true; 

     sRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(Recognized); 
    } 

    private static void Recognized(object obj, SpeechRecognizedEventArgs args) 
    { 
     controllers[args.Result.Text].TriggerCommand(args.Result.Text); 
    } 

    public static void AddCommands(string[] commands, IVoiceControlable control) 
    { 
     foreach (string str in commands) 
     { 
      controllers.Add(str, control); 
     } 

     sRecognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(commands)))); 
    } 
} 

有谁知道为什么'识别'不会被触发?

感谢您的任何帮助,非常感谢。

+0

在哪里调用'Initiate'? – 2012-07-14 16:32:08

+0

哦,是的,对不起,这也被称为,只是在主窗体的加载。 – Randomman159 2012-07-14 16:36:44

+0

您忘记为SpeechRecognitionRejected和AudioSignalProblemOccurred事件编写处理程序。 – 2012-07-14 18:09:24

回答

0

由于OpenGL运行游戏循环而不是事件侦听,线程完全被循环占用。要开始监听命令,需要第二个线程。