Following along with an answer I posted several months ago, I offer this suggestion.
Realize that I'm leaving out the SpeechFactory
class and much of the MySpeechMethods
class, please copy it from the other answer. Also, as noted in the other answer, you'll have to do some error handling. With that caveat, you would modify your own code this way.
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
var methods = new MySpeechMethods();
MethodInfo myMethod;
myMethod = SpeechFactory.GetSpeechMethod(e.Result.Text);
if(myMethod != null) return;
pBuilder.ClearContent();
pBuilder.AppendText(e.Result.Text);
sSynth.Speak(pBuilder);
}
Then in the MySpeechMethods
you would have your commands.
public class MySpeechMethods
{
[Speech("Open Notepad")]
public void OpenNotepad()
{
System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe");
}
//...