2015-05-25 30 views
-1

我一直在试图让我的代码,以便当我告诉它搜索它会问我想要搜索什么,然后将其添加到谷歌搜索URL所以它会寻找它我不能让我的语音识别来执行搜索

所以这将是https://www.google.co.uk/search?q= 加什么我为了寻找正确的东西

namespace AID 
{ 


    public partial class Form1 : Form 
    { 

     SpeechSynthesizer s = new SpeechSynthesizer(); 
     SpeechRecognitionEngine reg = new SpeechRecognitionEngine(); 



     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      string test = "12345".ToString().Replace("123", ""); 
      s.Speak("booting up"); 
      s.Speak("AID online"); 
      s.Speak("Hello sir, how may i assist you?"); 
      string[] commands = { "hello AID", "what are you", "how are you", "what's the time", "open music", "sing me a song", "thank you AID", "what does AID mean", "Tell me a joke", "i need to take notes", "i want to search the web" 
      ,"i want to check my mail","run lol","the yogscast","calabrate voice","where are you","tell me the truth","aid wakeup","aid exit"}; 
      reg.SetInputToDefaultAudioDevice(); 
      reg.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(commands)))); 
      reg.RecognizeAsync(RecognizeMode.Multiple); 
      reg.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec); 

     } 

     public string time() 
     { 
      DateTime n = DateTime.Now; 
      string o = n.GetDateTimeFormats('t')[0]; 
      return o; 
     } 

     public void rec(object sender, SpeechRecognizedEventArgs x) 
     { 

      string recString = x.Result.Text; 
      switch(recString) 
      { 
       case "hello AID": 
        s.Speak("Hello sir"); 
        break; 
       case "how are you": 
        s.Speak("I'm good, how are you?"); 
        break; 
       case "what's the time": 
        s.Speak(time()); 
        break; 
       case "open music": 
        s.Speak("on it sir"); 
        System.Diagnostics.Process.Start("wmplayer.exe"); 
        break; 
       case "sing me a song": 
        s.Speak("im a little tea pot short and stout here is my handle here is my spout if you poor me over hear me shout tip me up and poor me out"); 
        break; 
       case "thank you AID": 
        s.Speak("you are very welcome sir "); 
        break; 
       case "what are you": 
        s.Speak("I am AID"); 
        break; 
       case "what does AID mean": 
        s.Speak("Aid means assistance and intelligent device"); 
        break; 
       case "Tell me a joke": 
        s.Speak("I like my relationships like I like my source, open"); 
        break; 
       case "i need to take notes": 
        s.Speak("opening notepad now sir"); 
        System.Diagnostics.Process.Start("notepad.exe"); 
        break; 
       case "i want to search the web": 
        s.Speak("opening the web now sir"); 
        System.Diagnostics.Process.Start("chrome.exe"); 
        break; 
       case "i want to check my mail": 
        s.Speak("opening your inbox now sir"); 
        System.Diagnostics.Process.Start("https://mail.google.com/mail/u/0/#inbox"); 
        break; 
       case "run lol": 
        s.Speak("opening league of legends now sir");     
        System.Diagnostics.Process.Start(@"C:\Riot Games\League of Legends\lol.launcher.exe"); 
        break; 
       case "the yogscast": 
        s.Speak("opening the yogscast youtube channel now sir"); 
        System.Diagnostics.Process.Start("https://www.youtube.com/user/BlueXephos"); 
        break; 
       case "calabrate voice": 
        s.Speak("voice calabration complete"); 
        break; 
       case "where are you": 
        s.Speak("Im here"); 
        break; 
       case "tell me the truth": 
        s.Speak("the truth is all but lies "); 
        break; 
       case "aid wakeup": 
        s.Speak("Awake and awaiting further instruction sir"); 
        break; 



      } 
     } 
    } 
} 
+0

我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –

回答

0

您可以使用此发言:

System.Diagnostics.Process.Start("IExplore.exe", "https://www.google.co.uk/search?q=" + /*Your question text, querystring encoded variable*/); 

这将打开Internet Explorer

或者

System.Diagnostics.Process.Start("https://www.google.co.uk/search?q=" + /*Your question text, querystring encoded variable*/); 

打开默认浏览器。

编辑: 为了编码字符串查询字符串在C#中的格式,你可以做到这一点的方式如下:

string encodedString = HttpServerUtility.UrlEncode(yourString); 

所以基本上你必须:

System.Diagnostics.Process.Start("https://www.google.co.uk/search?q=" + encodedString) 
+0

关于我将如何做变量的任何想法,因为这是与 – poketis

+0

有问题的部分在你的情况下,你的编码字符串必须是recString。 – darkndream

+0

任何机会的一点帮助我不知道如何做到这一点在C#中我花了大部分时间与Java所以即时通讯仍然掌握与C#的差异,所以任何帮助,我可以得到很大。我明白整个添加一个字符串到结尾它更多地认识到添加字符串的语音 – poketis