I am currently testing the SpeechRecognitionEngine by loading from an xml file a pretty simple rule. In fact it is a simple between (\"decrypt the email\", \"remove encryp
If the only thing the System.Speech recognizer is listening for is "encrypt the email", then the recognizer will generate lots of false positives. (Particularly in a noisy environment.) If you add a DictationGrammar (particularly a pronunciation grammar) in parallel, the DictationGrammar will pick up the noise, and you can check the (e.g.) name of the grammar in the event handler to discard the bogus recognitions.
A (subset) example:
static void Main(string[] args)
{
Choices gb = new Choices();
gb.Add("encrypt the document");
gb.Add("decrypt the document");
Grammar commands = new Grammar(gb);
commands.Name = "commands";
DictationGrammar dg = new DictationGrammar("grammar:dictation#pronunciation");
dg.Name = "Random";
using (SpeechRecognitionEngine recoEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
recoEngine.SetInputToDefaultAudioDevice();
recoEngine.LoadGrammar(commands);
recoEngine.LoadGrammar(dg);
recoEngine.RecognizeCompleted += recoEngine_RecognizeCompleted;
recoEngine.RecognizeAsync();
System.Console.ReadKey(true);
recoEngine.RecognizeAsyncStop();
}
}
static void recoEngine_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
if (e.Result.Grammar.Name != "Random")
{
System.Console.WriteLine(e.Result.Text);
}
}