internal static void GrammarLoader(SpeechGUI x)
        {
            gui = x;

            Grammar grammar = new Grammar(MakeGrammarBuilder());

            recognizer.LoadGrammarAsync(grammar);
            recognizer.SetInputToDefaultAudioDevice();
            recognizer.SpeechRecognized          += Recognizer_SpeechRecognized;
            recognizer.SpeechRecognitionRejected += Recognizer_SpeechRecognitionRejected;
        }
Пример #2
0
        public static void Do(SpeechRecognizedEventArgs e, SpeechGUI gui)
        {
            //this function is equivalent to Akib.ProjectWork.response._recognizeSpeechAndMakeSureTheComputerSpeaksToYou_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            int mouseX = 32000;
            int mouseY = 32000;
            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();

            switch (e.Result.Text)
            {
            //test commands
            case "say hello":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("Hello!");
                break;

            case "print my name":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("Mockless");
                break;

            case "Goodbye":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("Goodbye");
                break;

            case "amar naam bolo":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak(" AKEEEB SHAHRIAR KHAN");

                break;

            case "Mockless":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("bolan sir");
                Thread.Sleep(500);
                speechSynthesizer.Dispose();
                break;

            case "vaat khaiso":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak(" ami vaat khai naa");
                Thread.Sleep(500);
                speechSynthesizer.Dispose();
                break;

            case "tor naam ki":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("umaar naam Mockless, ami baanglaa bollta paari.");
                Thread.Sleep(500);
                speechSynthesizer.Dispose();
                break;

            case "Sob kotha bujis":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("bujhi");    //doesnt work
                break;

            //Mouse Movement
            case "mouse narao":
                MouseControl.MoveTo(mouseX, mouseY);
                break;

            case "down":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                mouseY = mouseY + 5000;
                MouseControl.MoveTo(mouseX, mouseY);
                break;

            case "up":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                mouseY = mouseY - 5000;
                MouseControl.MoveTo(mouseX, mouseY);
                break;

            case "left":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                mouseX = mouseX - 5000;
                MouseControl.MoveTo(mouseX, mouseY);
                break;

            case "right":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                mouseX = mouseX + 5000;
                MouseControl.MoveTo(mouseX, mouseY);
                break;

            case "majh khaane":
                MouseControl.MoveTo(35000, 35000);
                break;

            case "click left":
                MouseControl.LeftClick();
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("LEFT BUTTON CLICKED");
                break;

            case "click right":
                MouseControl.RightClick();
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("RIGHT BUTTON CLICKED");
                break;

            //Calculator Commands
            case "calculator open koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                curProg = System.Diagnostics.Process.Start("calc");     //"calc" process started and the process is referred by curProg

                if (!pids.Contains("calc"))
                {
                    pids.Add(curProg.ProcessName);
                }
                //gui.LBLSpeechTextOut.Text = curProg.ProcessName;
                // pids has the string element "calc"
                speechSynthesizer.Speak("calculator open koresi");

                break;

            case "jog koro":
                speechSynthesizer.Speak("calculator a zog kortesi");
                SendKeys.Send("{ADD}");
                /// Thread.Sleep(500);
                break;

            case "biyog koro":
                SendKeys.Send("{SUBTRACT}");
                Thread.Sleep(500);
                break;

            case "goon koro":

                SendKeys.Send("{MULTIPLY}");
                Thread.Sleep(500);
                break;

            case "vaag koro":

                SendKeys.Send("{DIVIDE}");
                Thread.Sleep(500);
                break;

            case "ek":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{1}");
                break;

            case "dui":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                SendKeys.Send("{2}");

                break;

            case "teen":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                SendKeys.Send("{3}");

                break;

            case "chaar":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                SendKeys.Send("{4}");

                break;

            case "pach":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                SendKeys.Send("{5}");

                break;

            case "soy":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{6}");
                break;

            case "shaat":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{7}");
                break;

            case "aat":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{8}");
                break;

            case "noy":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{9}");
                break;

            case "shunno":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{0}");
                break;

            case "folafol":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{ENTER}");
                break;

            case "pesao":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{BS}");
                break;

            case "clear koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{ESC}");
                break;

            case "calculator close koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                if (pids.Contains("calc"))
                {
                    KillProcessAndChildren("Calculator");     //"Calculator" is the process name found from task manager.
                                                              //"calc" process name didnt exist. Using "calc" in this case, will return empty array from GetProcessByName()
                                                              //and in turn will cause an index out of bound error
                                                              //Additional Info: unlike Explorer, calculator creates ONE and ONLY ONE process for new calculator instance(s) as a result,
                                                              //TempProc[TempProc.Length-1].kill() will close all the instance at once.
                    pids.Remove("calc");
                    speechSynthesizer.Speak("calculator close koresi");
                    Thread.Sleep(500);
                }
                else
                {
                    speechSynthesizer.Speak("The Process is not running.");
                    Thread.Sleep(500);
                }
                break;

            //Windows Explorer
            case "my computer open koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                //System.Diagnostics.Process.Start("iexplore.exe", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}"); //File Explorer opened
                curProg  = System.Diagnostics.Process.Start("explorer", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}"); //File Explorer opened and referred by curProg
                procName = "explorer";
                pids.Add(procName);                                                                                  //pids has "calc", "explorer"
                Thread.Sleep(500);
                speechSynthesizer.Speak("my computer open koresi");
                speechSynthesizer.Dispose();
                break;

            case "go right":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{RIGHT}");
                break;

            case "go left":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{LEFT}");
                break;

            case "go up":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{UP}");
                break;

            case "go down":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{DOWN}");
                break;

            case "enter":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{ENTER}");
                break;

            case "back":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{BS}");
                break;

            case "copy":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("^c");
                break;

            case "paste":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("^v");
                break;

            case "sob nir ba chon karo":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("^a");
                break;

            case "refresh koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                KeyboardSend.KeyDown(Keys.F5);
                KeyboardSend.KeyUp(Keys.F5);
                break;

            case "desktop dekhao":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                KeyboardSend.KeyDown(Keys.LWin);
                KeyboardSend.KeyDown(Keys.D);
                KeyboardSend.KeyUp(Keys.LWin);
                KeyboardSend.KeyUp(Keys.D);
                break;

            case "niche scroll koro":

                SendKeys.Send("{DOWN} 10");
                break;

            case "upore scroll koro":

                SendKeys.Send("{UP} 10");
                break;

            case "screenshot nao":
                PrintScreen();
                break;

            case "my computer close koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;

                if (procName != null)
                {
                    KillProcessAndChildren(procName);

                    speechSynthesizer.Speak("my computer close koresi");
                    Thread.Sleep(500);
                }
                else
                {
                    speechSynthesizer.Speak("The Process is not running.");
                    Thread.Sleep(500);
                }
                break;

            //alt-F4
            case "close koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("%{F4}");
                speechSynthesizer.Speak("close korsi");

                break;

            //Browser control
            case "tab close koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("^{F4}");
                speechSynthesizer.Speak("Tab close koresi");
                break;

            case "program switch koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("program switch korsi");
                KeyboardSend.KeyDown(Keys.RWin);
                KeyboardSend.KeyDown(Keys.Tab);
                KeyboardSend.KeyUp(Keys.RWin);
                KeyboardSend.KeyUp(Keys.Tab);
                break;

            //Chrome Related
            case "face book login koro":
                System.Diagnostics.Process.Start("https://www.facebook.com/");
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("facebook a login koresi");
                break;

            case "you tube a jao to":
                System.Diagnostics.Process.Start("https://www.youtube.com/");
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("youtube open koresi");
                break;

            case "google a jao to":
                System.Diagnostics.Process.Start("https://www.google.com.bd/");
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("google open koresi");
                break;

            case "vues a login koro":
                curProg = System.Diagnostics.Process.Start("https://portal.aiub.edu/");
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                speechSynthesizer.Speak("V U E S portal open koresi");
                speechSynthesizer.Speak("login korun please");
                break;

            case "vues close koro":

                gui.LBLSpeechTextOut.Text = e.Result.Text;
                Process TempProc = Process.GetProcessById(Convert.ToInt32(curProg.Id.ToString()));
                TempProc.CloseMainWindow();
                TempProc.WaitForExit();
                speechSynthesizer.Speak("VUES close koresi");
                break;

            case "sound baaraao":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                ExecuteCommand("C:/nircmd.exe changesysvolume +8000");
                break;

            case "sound komaao":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                ExecuteCommand("C:/nircmd.exe changesysvolume -8000");
                break;

            case "soto koro":     //zoom out
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                KeyboardSend.KeyDown(Keys.ControlKey);
                SendKeys.Send("{SUBTRACT}");
                KeyboardSend.KeyUp(Keys.ControlKey);
                break;

            //Camera Related
            //case "camera open koro":
            //    gui.LBLSpeechTextOut.Text = e.Result.Text;
            //    curProg = Process.Start("Camera.exe");
            //    pids.Add(curProg.ProcessName);
            //    Camera camera = new Camera();
            //    speechSynthesizer.Speak("camera open koresi");
            //    break;
            case "boro koro":     //zoom in
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                KeyboardSend.KeyDown(Keys.ControlKey);
                SendKeys.Send("{ADD}");
                KeyboardSend.KeyUp(Keys.ControlKey);
                break;

            case "muse felo":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{DEL}");
                break;

            case "tab dao":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("{TAB}");
                break;

            case "windows menu open koro":
                gui.LBLSpeechTextOut.Text = e.Result.Text;
                SendKeys.Send("^{ESC}");
                break;
            }
        }