I need help. I want to make an application that will recognize what I am saying and do stuff that I say. For example:
If I say open [notepad]
, where [notepad]
can be any application name, it needs to open notepad.
I think I need to use both Grammar and DictationGrammar, but I don't know how. Please help me. Thanks.
My code now looks like this:
string WelcomeSentence = "Hello sir, how are you today";
SpeechSynthesizer sSynth = new SpeechSynthesizer();
PromptBuilder pBuilder = new PromptBuilder();
SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
private void frmMain_Load(object sender, EventArgs e)
{
sSynth.SelectVoice("IVONA Amy");
sSynth.SetOutputToDefaultAudioDevice();
pBuilder.ClearContent();
pBuilder.AppendText(WelcomeSentence);
sSynth.Speak(pBuilder);
Choices sList = new Choices();
sList.Add(File.ReadAllLines(@"Commands.ekd"));
Grammar gr = new Grammar(new GrammarBuilder(sList));
DictationGrammar dgr = new DictationGrammar();
try
{
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
sRecognize.Recognize();
}
catch { return; }
}
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "open notepad")
{
System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe");
}
else
{
pBuilder.ClearContent();
pBuilder.AppendText(e.Result.Text);
sSynth.Speak(pBuilder);
}
}
Please help.
Grammar
andDictationGrammar
. It would appear that you are loading them both properly, but I dont know the nuance of your speech engine to say. – crthompson