Scenario :
I have 2 commands.
1) Search Google for "any word here"
2) Open application "any word here"
Problem :
Since the word after "Search Google for" can be anything, how am I suppose to know what am I going to write for my IF statements?
With pre-defined sentences, I can do it easily like
void Engine_SpeechRecognized (object sender, SpeechRecognizedEventsArgs e)
{
if (e.Result.Text == "Search Google Stackoverflow")
{
Search("Stackoverflow");
}
}
But since now it's not pre-defined, what am I suppose to write for my IF statement condition? It's not like I can do this,
if (e.Result.Text == "Search Google" + e.Result.Text)
{
Search(e.Result.Text);
}
So, how am I going to do it? This is easy if I only have 1 command and need only to execute 1 action, then I could just set the default action as Search(), but now the case's different.
Here is my code ( For only 1 command & action , I NEED 2 and above) * Using System.Speech
public MainWindow()
{
InitializeComponent();
builder.Append("search google for"); builder.AppendDictation();
Grammar grammar = new Grammar(builder);
grammar.Name = ("Google Searching");
engine.LoadGrammarAsync(grammar);
engine.SetInputToDefaultAudioDevice();
engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(Engine_SpeechRecognized);
engine.RecognizeAsync(RecognizeMode.Multiple);
}
string result;
void Engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
txtSpeech.Text = e.Result.Text;
ExtractKeywords(e.Result.Text);
OpenApp("https://www.google.com/#q=" + result);
}