First, include the System.Speech library.
My code, for a console application, is the next:
using System.Speech.Recognition
namespace SpeechRecognition
{
static class Program
{
static void Main(string[] args)
{
SpeechRecognizer sr = new SpeechRecognizer();
sr.LoadGrammar(new Grammar(new GrammarBuilder("First test")));
sr.LoadGrammar(new Grammar(new GrammarBuilder("Second test")));
sr.SpeechRecognized += new EventHandler<speechrecognizedeventargs>
(sr_SpeechRecognized);
}
static void sr_SpeechRecognized(object sender,
SpeechRecognizedEventArgs e)
{
Console.WriteLine(e.Result.Text);
}
}
}
When you say "First test", you'll find "First test" on the console.
When you say "Second test", you'll find "Second test" on the console.