我有一个 void 方法(希望我说得对),它初始化语音识别引擎、语法和一些用于获取命令的文本文件的路径。现在我已经将代码放在一个 void 方法中,以便我可以在 From_Load 事件中调用它,但是由于某种原因,如果 PC 进入睡眠状态然后再备份,语音识别将不起作用,我设置了一个计时器来调用方法每十分钟。现在语音识别和语法每十分钟重新初始化一次,但我不确定它是初始化两次还是第一个自动终止,如果没有,是否可以这样做?
public void InitGrammar()
{
#region Recengine, grammar, commands
try
{
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
//Grammar DGrammar = new DictationGrammar();
//recEngine.LoadGrammar(DGrammar);
Choices commands = new Choices();
Choices Ecommands = new Choices();
Ecommands.Add(new string[] { "Emergency shutdown", "Reboot", "Abort", "Abort Abort" });
commands.Add(File.ReadAllLines(@"C:\Natalie\commands\commands.txt"));
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
synthesizer.SelectVoiceByHints(VoiceGender.Female);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += RecEngine_SpeechRecognized;
recEngine.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception exinit)
{
_Errorsound.Play();
MessageBox.Show(exinit.Message);
}
synthesizer.SelectVoiceByHints(VoiceGender.Female);
#endregion
}
三国纷争
相关分类