有人能告诉我怎么解决这个问题吗?它只搜索我在Commands.txt中写的关键字。当它问我你想搜索什么时,_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")))));会问我什么?我说的是" banana“,但是banana没有包含在Commands.txt中,所以它不会做任何事情。
井。我想让它像这样。当你说我想搜索什么(它会问你想搜索什么),然后你想说任何东西(水果,酒店,人,动物,所有你要说的词)。它应该出现在google搜索栏上
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);
}
发布于 2016-03-31 03:10:49
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);
}https://stackoverflow.com/questions/32207104
复制相似问题