2015-05-24 51 views
0

我想要的是,当我要求我的程序打开Chrome时,它会问我想要什么。如何使用语音识别来执行网络搜索

搜索和我说我想搜索,它搜索它,但我有一些问题,我也无法找到很多网上。

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" }; 
      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; 

      } 
     } 
    } 
} 

正如你可以看到我有一个功能,我说我要寻找它开始使用Chrome上网,但我希望能够使用语音搜索。

例如:

  • 我想在网上搜索

  • 那你想搜索

然后,它会搜索什么,我问它来搜索。

回答