0

Can someone please tell me how to fix this? It only search for the keywords I wrote inside the Commands.txt. _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt"))))); When it asks me what do you want to search? I say "banana" but banana is not included in the Commands.txt so it will not do anything.

Well. I want it to be like. When you say I WANT TO SEARCH SOMETHING (it will ask what do you want to search) then you wanna say anything (fruits, hotels, people, animals all the words that you will say). it should appear on google search bar

if (speech == "I WANT TO SEARCH SOMETHING")
{
    QEvent = speech;
    ENZO.SpeakAsync("what do you want to search");
    speech = string.Empty;
}
else if (speech != string.Empty && QEvent == "I WANT TO SEARCH SOMETHING")
{
    Process.Start("http://google.com/search?q=" + speech);
    QEvent = string.Empty;


    if (ranNum < 6) { ENZO.SpeakAsync("Alright, I am searching " + speech + " in google"); }
    else if (ranNum > 5) { ENZO.SpeakAsync("ok sir, I am searching " + speech); }
    speech = string.Empty;
}

I have also tried the code below but after saying stuffs for it only opens the google but didn't search anything.

    if (speech.ToLower().Contains("search for")) // See if the string contains the 'search for' string.
    {
         string query = speech.Replace("search for", ""); // Remove the 'search for' text.
         // Old code (does not make the text fully URL safe)
         // query = query.Replace(' ', '+'); 
         query = System.Web.HttpUtility.UrlEncode(query);
         string url = "https://www.google.com.au/search?q=" + query;
         System.Diagnostics.Process.Start(url);
    }
user193142
  • 11
  • 3

1 Answers1

-1
if (speech.ToLower().Contains("search for")) // See if the string contains the 'search for' string.
{
     string query = speech.Replace("search for", ""); // Remove the 'search for' text.
     // Old code (does not make the text fully URL safe)
     // query = query.Replace(' ', '+'); 
     query = System.Web.HttpUtility.UrlEncode(query);
     string url = "https://www.google.com.au/search?q=" + query;
     System.Diagnostics.Process.Start(url);
}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92