首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌,脸书语音搜索(语音识别C#)

谷歌,脸书语音搜索(语音识别C#)
EN

Stack Overflow用户
提问于 2015-08-25 22:43:13
回答 1查看 436关注 0票数 0

有人能告诉我怎么解决这个问题吗?它只搜索我在Commands.txt中写的关键字。当它问我你想搜索什么时,_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")))));会问我什么?我说的是" banana“,但是banana没有包含在Commands.txt中,所以它不会做任何事情。

井。我想让它像这样。当你说我想搜索什么(它会问你想搜索什么),然后你想说任何东西(水果,酒店,人,动物,所有你要说的词)。它应该出现在google搜索栏上

代码语言:javascript
复制
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;
}

我也试过下面的代码,但在说完东西之后,它只打开了谷歌,但没有搜索任何东西。

代码语言:javascript
复制
    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);
    }

EN

回答 1

Stack Overflow用户

发布于 2016-03-31 03:10:49

代码语言:javascript
复制
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);
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32207104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档