Beispiel #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Speak speak = new Speak();
            //speak.introduceMyself();

            Thread thread1 = new Thread(ListenToCall);

            thread1.Start();
            // Create an in-process speech recognizer for the en-US locale.
            Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");



            Choices choices = new Choices();

            choices.Add(new string[] { "help me stephen", "Play song", "F**k", "Open Spotify", "Shutdown",
                                       "Yes", "No", "Open Chrome", "Open Settings", "Next song", "Previous song",
                                       "Volume up", "Volume down", "Thank you", "Hello stephen", "what's the current time", "what day is it", "Search google", "what's the current weather", "listen", "kici kici tash tash",
                                       "what's the current CoronaVirus status" });

            var gb = new GrammarBuilder(choices);

            gb.Culture = recognizer.RecognizerInfo.Culture;
            var g = new Grammar(gb);

            // Create and load a dictation grammar.
            //recognizer.LoadGrammar(new DictationGrammar());
            recognizer.LoadGrammar(g);
            // Add a handler for the speech recognized event.
            recognizer.SpeechRecognized +=
                new EventHandler <SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

            // Configure input to the speech recognizer.
            recognizer.SetInputToDefaultAudioDevice();

            // Start asynchronous, continuous speech recognition.
            recognizer.RecognizeAsync(RecognizeMode.Multiple);
        }
Beispiel #2
0
        public void ListenToCall()
        {
            while (true)
            {
                Speak speak = new Speak();
                switch (recognizedText)
                {
                case "help me stephen":
                    speak.CalledFor();
                    recognizedText = "";
                    break;

                case "f**k":
                    speak.DontSwear();
                    recognizedText = "";
                    break;

                case "open spotify":
                    speak.OpenSpotify();
                    recognizedText = "";
                    break;

                case "shutdown":
                    speak.Shutdown();
                    recognizedText = "";
                    Thread.Sleep(2000);
                    if (recognizedText == "yes")
                    {
                        speak.ShutdownApproved();
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        speak.ShutdownCancelled();
                    }
                    recognizedText = "";
                    break;

                case "open chrome":
                    speak.OpenChrome();
                    recognizedText = "";
                    break;

                case "open settings":
                    speak.OpenSettings();
                    recognizedText = "";
                    break;

                case "play song":
                    PlaySong();
                    recognizedText = "";
                    break;

                case "next song":
                    NextSong();
                    recognizedText = "";
                    break;

                case "previous song":
                    PreviousSong();
                    recognizedText = "";
                    break;

                case "volume down":
                    for (int i = 0; i < amount; i++)
                    {
                        VolumeDown();
                        Thread.Sleep(20);
                    }
                    recognizedText = "";
                    break;

                case "volume up":
                    for (int i = 0; i < amount; i++)
                    {
                        VolumeUp();
                        Thread.Sleep(20);
                    }
                    recognizedText = "";
                    break;

                case "tell me something about gimper's group":
                    speak.Hajsownicy();
                    recognizedText = "";
                    break;

                case "thank you":
                    speak.Welcome();
                    recognizedText = "";
                    break;

                case "hello stephen":
                    speak.hello();
                    recognizedText = "";
                    break;

                case "what's the current time":
                    speak.currentTime();
                    recognizedText = "";
                    break;

                case "what day is it":
                    speak.currentDate();
                    recognizedText = "";
                    break;

                case "search google":
                    speak.SearchGoogle();
                    recognizedText    = "";
                    isLookingInGoogle = true;
                    DictationGrammar dictation = new DictationGrammar();
                    recognizer.UnloadAllGrammars();
                    recognizer.LoadGrammarAsync(dictation);
                    Thread.Sleep(6000);
                    Chrome(googleRecognizedText);
                    googleRecognizedText = "";
                    Choices choices = new Choices();
                    choices.Add(new string[] { "help me stephen", "Play song", "F**k", "Open Spotify", "Shutdown",
                                               "Yes", "No", "Open Chrome", "Open Settings", "Next song", "Previous song",
                                               "Volume up", "Volume down", "Thank you", "Hello stephen",
                                               "what's the current time", "what day is it", "Search google", "What's the current weather" });

                    var gb = new GrammarBuilder(choices);
                    gb.Culture = recognizer.RecognizerInfo.Culture;
                    var g = new Grammar(gb);
                    recognizer.LoadGrammarAsync(g);
                    recognizer.UnloadGrammar(dictation);
                    isLookingInGoogle = false;
                    break;

                case "what's the current weather":
                    WeatherForecast forecast = new WeatherForecast();
                    speak.currentWeather();
                    recognizedText = "";
                    break;

                case "listen":
                    speak.ListenKurwa();
                    recognizedText = "";
                    break;

                case "kici kici tash tash":
                    SoundPlayer player = new SoundPlayer();
                    player.SoundLocation = AppDomain.CurrentDomain.BaseDirectory + "\\do lwa.wav";
                    player.Play();
                    recognizedText = "";
                    break;

                case "what's the current coronavirus status":
                    CoronaVirus corona = new CoronaVirus();
                    //corona.GetCoronaStatusForPoland();
                    speak.CoronaVirusNotImplemented();
                    recognizedText = "";
                    break;
                }
            }
        }