我正在尝试构建一个识别我的命令和工作的程序。我能够做到,但现在我想在这个程序中添加谷歌搜索。它将识别我的命令并在互联网上搜索它。
private void Main_Load(object sender, EventArgs e)
{
cmds.Add(new String[] { "Hello", "Good Morning", "Time please"}); /*here are the commands */
Grammar gRmr = new Grammar(new GrammarBuilder(cmds));
try
{
recEng.RequestRecognizerUpdate();
recEng.LoadGrammar(gRmr);
recEng.SpeechRecognized += recEng_SpeechRecognized;
recEng.SetInputToDefaultAudioDevice();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void btnStartSpkr_Click(object sender, EventArgs e)
{
recEng.RecognizeAsync(RecognizeMode.Multiple);
btnStpSpkr.Enabled = true;
btnStartSpkr.Enabled = false;
}
void recEng_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text.ToString())
{
case "Hello":
synth.SpeakAsync("Hello. How are you doing?");
break;
case "Time please" :
synth.SpeakAsync("Current time is " + DateTime.Now.ToLongTimeString()); /*Says current time*/
break;
case "Good Morning" :
synth.SpeakAsync("Good Morning, Have a good day ahead"); /*It says good morning */
break;
default :
/**Here I want to add Google search. I mean if I say America it will search America in Google. Can't understand how to do it.**/