I have a void method (hopefully i am saying it correctly) that initializes a speech recognition engine, grammar and some paths for a text files to get the commands from. Now i have put the code inside a void method so that i can call it in the From_Load event but since for some reason the speech recognition does not work if the PC went to sleep and then back up, i setup a timer to call upon the method every ten min. Now the speech recog and grammar is re-initialized every ten min but im not sure if it is initialized twice or the first one is automatically terminated, if not, is it possible to do it?
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
}