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))));
}
}
有誰知道爲什麼'識別'不會被觸發?
感謝您的任何幫助,非常感謝。
在哪裏調用'Initiate'? – 2012-07-14 16:32:08
哦,是的,對不起,這也被稱爲,只是在主窗體的加載。 – Randomman159 2012-07-14 16:36:44
您忘記爲SpeechRecognitionRejected和AudioSignalProblemOccurred事件編寫處理程序。 – 2012-07-14 18:09:24