C# 我能';我无法让语音识别执行搜索

C# 我能';我无法让语音识别执行搜索,c#,speech-recognition,C#,Speech Recognition,我一直在尝试获取我的代码,这样当我告诉它搜索时,它会问我要搜索什么,然后将其添加到Google搜索URL的末尾,这样它就会搜索它 是的 加上我所说的,为了寻找正确的东西 namespace AID { public partial class Form1 : Form { SpeechSynthesizer s = new SpeechSynthesizer(); SpeechRecognitionEngine reg = new Speec

我一直在尝试获取我的代码,这样当我告诉它搜索时,它会问我要搜索什么,然后将其添加到Google搜索URL的末尾,这样它就会搜索它

是的 加上我所说的,为了寻找正确的东西

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;



            }
        }
    }
}
名称空间辅助
{
公共部分类Form1:Form
{
SpeechSynthesizer s=新的SpeechSynthesizer();
SpeechRecognitionEngine reg=新建SpeechRecognitionEngine();
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
字符串test=“12345”.ToString().Replace(“123”,”);
s、 说话(“启动”);
s、 发言(“在线援助”);
s、 说话(“你好,先生,我能为您效劳吗?”);
string[]commands={“你好,艾德”,“你好”,“你好”,“现在几点了”,“打开音乐”,“给我唱首歌”,“谢谢艾德”,“艾德是什么意思”,“给我讲个笑话”,“我需要做笔记”,“我想搜索网页”
,“我想查看我的邮件”,“快跑lol”,“瑜珈师”,“卡拉布拉特之声”,“你在哪里”,“告诉我真相”,“援助唤醒”,“援助退出”};
reg.setInputOdeFaultAudioDevice();
reg.LoadGrammar(新语法(新语法生成器(新选项(命令)));
reg.RecognizeAsync(RecognizeMode.Multiple);
reg.speechrecogned+=新事件处理程序(rec);
}
公共字符串时间()
{
DateTime n=DateTime.Now;
字符串o=n.GetDateTimeFormats('t')[0];
返回o;
}
public void rec(对象发送方,SpeechRecognizedEventArgs x)
{
string recString=x.Result.Text;
开关(recString)
{
案例“hello AID”:
s、 说(“你好先生”);
打破
案例“你好吗”:
s、 说(“我很好,你好吗?”);
打破
案例“几点了”:
s、 说话(时间);
打破
案例“开放音乐”:
s、 说(“在上面,先生”);
System.Diagnostics.Process.Start(“wmplayer.exe”);
打破
案例“给我唱首歌”:
s、 说话(“我是一个小茶壶,又矮又胖,这是我的把手,这是我的壶嘴,如果你可怜我,请听我喊叫,把我倒出来,可怜我”);
打破
案例“感谢援助”:
s、 说话(“非常欢迎您,先生”);
打破
案例“你是什么”:
s、 说话(“我是援助”);
打破
案例“援助意味着什么”:
s、 说话(“Aid指协助和智能设备”);
打破
案例“给我讲个笑话”:
s、 说话(“我喜欢我的关系就像我喜欢我的来源一样,开放”);
打破
案例“我需要做笔记”:
s、 说话(“现在打开记事本,先生”);
System.Diagnostics.Process.Start(“notepad.exe”);
打破
案例“我想搜索网络”:
s、 说话(“现在打开网络,先生”);
System.Diagnostics.Process.Start(“chrome.exe”);
打破
案例“我想检查我的邮件”:
s、 说话(“现在打开你的收件箱,先生”);
系统.诊断.进程.启动(“https://mail.google.com/mail/u/0/#inbox");
打破
案例“运行lol”:
s、 说(“现在是传奇联盟的开幕式,先生”);
System.Diagnostics.Process.Start(@“C:\Riot Games\League of Legends\lol.launcher.exe”);
打破
案例“瑜伽士”:
s、 说话(“现在打开yogscast youtube频道,先生”);
系统.诊断.进程.启动(“https://www.youtube.com/user/BlueXephos");
打破
案例“卡拉布拉特之声”:
s、 说话(“语音校准完成”);
打破
案例“你在哪里”:
s、 说话(“我在这里”);
打破
案例“告诉我真相”:
s、 说话(“事实就是谎言”);
打破
案例“援助唤醒”:
s、 说话(“醒来并等待进一步指示,先生”);
打破
}
}
}
}
您可以使用以下功能:

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

打开默认资源管理器

编辑: 要将字符串编码为C#中的querystring格式,可以通过以下方式进行:

string encodedString = HttpServerUtility.UrlEncode(yourString);
所以基本上你必须:

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

我已经编辑了你的标题。请参见“”,其中的共识是“不,他们不应该”.有没有关于如何处理变量的想法,因为这是我在您的案例中遇到的问题,您的编码字符串必须是recString。有没有可能得到一些帮助,我想不出如何在c中处理它?我大部分时间都花在java上,所以我仍然掌握着与c的区别,所以我能得到的任何帮助都将是非常好的。我理解在结尾加上一个字符串更像是语音识别加上字符串
System.Diagnostics.Process.Start("https://www.google.co.uk/search?q=" + encodedString)