有人可以告诉我如何解决这个问题吗?它只搜索我在Commands.txt中编写的关键字。 _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")))));
当它问我想要搜索什么时?我说"香蕉"但是banana不包含在Commands.txt中,所以它不会做任何事情。
好。我希望它像。当你说我想要搜索某些东西时(它会问你想搜索什么)然后你想说什么(水果,酒店,人,动物你会说的所有单词)。它应该出现在谷歌搜索栏上
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;
}
我也尝试了下面的代码,但在说完它的东西之后只打开谷歌但没有搜索任何东西。
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);
}
&#13;
答案 0 :(得分:-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);
}