public void CreateMouseMoveAndClickCommandGrammar(SpeechRecognizer speechRecognizer)
        {
            Choices choices = new Choices();

            for (int counter = 1; counter < 100; counter++)
            {
                choices.Add($"Mouse Down {counter}");
                choices.Add($"Mouse Up {counter}");
                choices.Add($"Mouse Left {counter}");
                choices.Add($"Mouse Right {counter}");
            }
            for (int counter = 150; counter < 800; counter = counter + 50)
            {
                choices.Add($"Mouse Down {counter}");
                choices.Add($"Mouse Up {counter}");
                choices.Add($"Mouse Left {counter}");
                choices.Add($"Mouse Right {counter}");
            }
            Grammar grammar = new Grammar(choices);

            grammar.Name = "Mouse Move";
            speechRecognizer.LoadGrammarAsync(grammar);
            Choices choicesClick = new Choices();

            choicesClick.Add("Mouse Click");
            choicesClick.Add("Click");
            choicesClick.Add("Left Click");
            choicesClick.Add("Right Click");
            choicesClick.Add("Double Click");
            Grammar grammarClick = new Grammar(choicesClick);

            grammarClick.Name = "Mouse Click";
            speechRecognizer.LoadGrammarAsync(grammarClick);
        }
        public void SetUpSymbolGrammarCommands(SpeechRecognizer speechRecognizer)
        {
            Choices choices = new Choices();

            choices.Add("Square Brackets");
            choices.Add("Brackets");
            choices.Add("Curly Brackets");
            choices.Add("Single Quotes");
            choices.Add("Apostrophes");
            choices.Add("Quotes");
            choices.Add("At Signs");
            choices.Add("Chevrons");
            choices.Add("Equals");
            choices.Add("Not Equal");
            choices.Add("Plus");
            choices.Add("Dollar");
            choices.Add("Hash");
            choices.Add("Pipes");
            choices.Add("Ampersands");
            Choices        choicesInOut   = new Choices("In", "Out", "Space");
            GrammarBuilder grammarBuilder = new GrammarBuilder();

            grammarBuilder.Append(choices);
            grammarBuilder.Append(choicesInOut);
            Grammar grammarSymbols = new Grammar(grammarBuilder)
            {
                Name = "Symbols"
            };

            speechRecognizer.LoadGrammarAsync(grammarSymbols);
        }
        public void LoadGrammarMouseCommands(SpeechRecognizer speechRecognizer)
        {
            List <string> screenCoordinates = new List <string> {
                "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Qubec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "1", "2", "3", "4", "5", "6", "7", "Zero"
            };
            Choices       choices      = new Choices();
            List <string> monitorNames = new List <string> {
                "Left", "Right", "Click", "Touch"
            };

            foreach (var item in screenCoordinates)
            {
                foreach (var monitorName in monitorNames)
                {
                    foreach (var item2 in screenCoordinates)
                    {
                        if (item2 == "Uniform")
                        {
                            break;
                        }
                        choices.Add($"{monitorName} {item} {item2}");
                    }
                }
            }
            GrammarBuilder grammarBuilder = new GrammarBuilder(choices);
            Grammar        grammar        = new Grammar((GrammarBuilder)grammarBuilder);

            grammar.Name = "Mouse";
            speechRecognizer.LoadGrammarAsync(grammar);
        }
Beispiel #4
0
 private void Grammar_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (audioStarted)
     {
         SpeechRecognizer.LoadGrammarAsync(GetCurrentGrammar());
     }
 }
        public void BuildPhoneticAlphabetGrammars(SpeechRecognizer speechRecogniser)
        {
            Choices        phoneticAlphabet = new Choices(new string[] { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Qubec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "Space" });
            GrammarBuilder grammarBuilder2  = new GrammarBuilder();

            grammarBuilder2.Append(phoneticAlphabet);
            grammarBuilder2.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilder3 = new GrammarBuilder();

            grammarBuilder3.Append(phoneticAlphabet);
            grammarBuilder3.Append(phoneticAlphabet);
            grammarBuilder3.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilder4 = new GrammarBuilder();

            grammarBuilder4.Append(phoneticAlphabet);
            grammarBuilder4.Append(phoneticAlphabet);
            grammarBuilder4.Append(phoneticAlphabet);
            grammarBuilder4.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilder5 = new GrammarBuilder();

            grammarBuilder5.Append(phoneticAlphabet);
            grammarBuilder5.Append(phoneticAlphabet);
            grammarBuilder5.Append(phoneticAlphabet);
            grammarBuilder5.Append(phoneticAlphabet);
            grammarBuilder5.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilder6 = new GrammarBuilder();

            grammarBuilder6.Append(phoneticAlphabet);
            grammarBuilder6.Append(phoneticAlphabet);
            grammarBuilder6.Append(phoneticAlphabet);
            grammarBuilder6.Append(phoneticAlphabet);
            grammarBuilder6.Append(phoneticAlphabet);
            grammarBuilder6.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilder7 = new GrammarBuilder();

            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            grammarBuilder7.Append(phoneticAlphabet);
            Choices phoneticAlphabet2to7     = new Choices(new GrammarBuilder[] { grammarBuilder2, grammarBuilder3, grammarBuilder4, grammarBuilder5, grammarBuilder6, grammarBuilder7 });
            Grammar grammarPhoneticAlphabets = new Grammar((GrammarBuilder)phoneticAlphabet2to7);

            grammarPhoneticAlphabets.Name = "Phonetic Alphabet";
            speechRecogniser.LoadGrammarAsync(grammarPhoneticAlphabets);
            Choices choicesLower = new Choices("Lower");

            BuildPhoneticAlphabetGrammars(speechRecogniser, phoneticAlphabet, choicesLower, "Phonetic Alphabet Lower");
            Choices choicesMixed = new Choices("Mixed");

            BuildPhoneticAlphabetGrammars(speechRecogniser, phoneticAlphabet, choicesMixed, "Phonetic Alphabet Mixed");
        }
        private static void BuildPhoneticAlphabetGrammars(SpeechRecognizer speechRecognizer, Choices phoneticAlphabet, Choices choices, string grammarName)
        {
            GrammarBuilder grammarBuilderLower2 = new GrammarBuilder();

            grammarBuilderLower2.Append(choices);
            grammarBuilderLower2.Append(phoneticAlphabet);
            grammarBuilderLower2.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilderLower3 = new GrammarBuilder();

            grammarBuilderLower3.Append(choices);
            grammarBuilderLower3.Append(phoneticAlphabet);
            grammarBuilderLower3.Append(phoneticAlphabet);
            grammarBuilderLower3.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilderLower4 = new GrammarBuilder();

            grammarBuilderLower4.Append(choices);
            grammarBuilderLower4.Append(phoneticAlphabet);
            grammarBuilderLower4.Append(phoneticAlphabet);
            grammarBuilderLower4.Append(phoneticAlphabet);
            grammarBuilderLower4.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilderLower5 = new GrammarBuilder();

            grammarBuilderLower5.Append(choices);
            grammarBuilderLower5.Append(phoneticAlphabet);
            grammarBuilderLower5.Append(phoneticAlphabet);
            grammarBuilderLower5.Append(phoneticAlphabet);
            grammarBuilderLower5.Append(phoneticAlphabet);
            grammarBuilderLower5.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilderLower6 = new GrammarBuilder();

            grammarBuilderLower6.Append(choices);
            grammarBuilderLower6.Append(phoneticAlphabet);
            grammarBuilderLower6.Append(phoneticAlphabet);
            grammarBuilderLower6.Append(phoneticAlphabet);
            grammarBuilderLower6.Append(phoneticAlphabet);
            grammarBuilderLower6.Append(phoneticAlphabet);
            grammarBuilderLower6.Append(phoneticAlphabet);
            GrammarBuilder grammarBuilderLower7 = new GrammarBuilder();

            grammarBuilderLower7.Append(choices);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            grammarBuilderLower7.Append(phoneticAlphabet);
            Choices phoneticAlphabetLower2to7 = new Choices(new GrammarBuilder[] { grammarBuilderLower2, grammarBuilderLower3, grammarBuilderLower4, grammarBuilderLower5, grammarBuilderLower6, grammarBuilderLower7 });
            Grammar grammarPhoneticAlphabets  = new Grammar((GrammarBuilder)phoneticAlphabetLower2to7);

            grammarPhoneticAlphabets.Name = grammarName;
            speechRecognizer.LoadGrammarAsync(grammarPhoneticAlphabets);
        }
        private void CreateDictationGrammar(SpeechRecognizer speechRecognizer, string initialPhrase, string grammarName, bool openEnded = false)
        {
            GrammarBuilder grammarBuilder = new GrammarBuilder();

            grammarBuilder.Append(new Choices(initialPhrase));
            if (openEnded)
            {
                grammarBuilder.AppendDictation();
            }

            Grammar grammar = new Grammar((GrammarBuilder)grammarBuilder);

            grammar.Name = grammarName;
            speechRecognizer.LoadGrammarAsync(grammar);
        }
Beispiel #8
0
        public void CreateRepeatableCommand(SpeechRecognizer speechRecognizer, string spokenCommand, string grammarName = null, int maximumRepeat = 10)
        {
            Choices choices = new Choices();

            for (int counter = 1; counter < maximumRepeat; counter++)
            {
                choices.Add($"{spokenCommand} {counter}");
            }
            Grammar grammar = new Grammar(choices);

            if (grammarName == null)
            {
                grammarName = spokenCommand;
            }
            grammar.Name = grammarName;
            speechRecognizer.LoadGrammarAsync(grammar);
        }
Beispiel #9
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (enableBtn == true)
     {
         recEngine.LoadGrammarAsync(movementGrammar);
         btn1.AccessibleName = "Voice Control Enabled";
         btn1.Text           = "Voice Control Enabled";
         richTextBox1.Text  += "Enabling Command Logging\n";
         enableBtn           = false;
     }
     else if (enableBtn == false)
     {
         recEngine.UnloadGrammar(movementGrammar);
         btn1.AccessibleName = "Voice Control Disabled";
         btn1.Text           = "Voice Control Disabled";
         richTextBox1.Text  += "Disabling Command Logging\n";
         enableBtn           = true;
     }
 }
        public void LoadMoveCommandsGrammar(SpeechRecognizer speechRecognizer)
        {
            Choices choices = new Choices();

            choices.Add("Move Down");
            choices.Add("Move Up");
            choices.Add("Move Left");
            choices.Add("Move Right");
            for (int counter = 1; counter < 50; counter++)
            {
                choices.Add($"Move Down {counter}");
                choices.Add($"Move Up {counter}");
                choices.Add($"Move Left {counter}");
                choices.Add($"Move Right {counter}");
            }
            Grammar grammar = new Grammar(choices)
            {
                Name = "Move Command"
            };

            speechRecognizer.LoadGrammarAsync(grammar);
        }
        public void LoadGrammarMouseHorizontalPositionCommands(SpeechRecognizer speechRecognizer)
        {
            List <string> screenCoordinates = new List <string> {
                "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Qubec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "1", "2", "3", "4", "5", "6", "7", "Zero"
            };
            Choices       choices             = new Choices();
            List <string> horizontalPositions = new List <string> {
                "Taskbar", "Ribbon", "Menu"
            };

            foreach (var screenCoordinate in screenCoordinates)
            {
                foreach (var horizontalPosition in horizontalPositions)
                {
                    choices.Add($"{horizontalPosition} {screenCoordinate}");
                }
            }
            GrammarBuilder grammarBuilder = new GrammarBuilder(choices);
            Grammar        grammar        = new Grammar((GrammarBuilder)grammarBuilder);

            grammar.Name = "Horizontal Position Mouse";
            speechRecognizer.LoadGrammarAsync(grammar);
        }
        public void addCommentToLocation(string streamOfComment, string latitude , string longitude)
        {
            SpeechAudioFormatInfo audioType = new SpeechAudioFormatInfo(1000,AudioBitsPerSample.Sixteen,AudioChannel.Mono);
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            byte[] streamString;
            Locations location = new Locations();
            byte[] buffer = new byte[10];
            MemoryStream stream = new MemoryStream();
            using (SpeechRecognitionEngine speechRecongnizeEngine = new SpeechRecognitionEngine())
            {
                location.latitude = Convert.ToDouble(latitude);
                location.longitude = Convert.ToDouble(longitude);
                locationsServices.addLocations(location);

                streamString = serializer.Deserialize<byte[]>(streamOfComment);
                buffer = new byte[streamString.Count()];

                stream.Write(buffer, 0, buffer.Length);

                // Add a handler for the LoadGrammarCompleted event.
                speechRecongnizeEngine.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(speechRecongnizeEngine_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                speechRecongnizeEngine.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>(speechRecongnizeEngine_SpeechRecognized);

                speechRecongnizeEngine.LoadGrammar(new DictationGrammar());
                speechRecongnizeEngine.SetInputToAudioStream(stream, audioType);
                speechRecongnizeEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {

                // Create SemanticResultValue objects that contain cities and airport codes.
                SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
                SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
                SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
                SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");

                // Create a Choices object and add the SemanticResultValue objects, using
                // implicit conversion from SemanticResultValue to GrammarBuilder
                Choices cities = new Choices();
                cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

                // Build the phrase and add SemanticResultKeys.
                GrammarBuilder chooseCities = new GrammarBuilder();
                chooseCities.Append("I want to fly from");
                chooseCities.Append(new SemanticResultKey("origin", cities));
                chooseCities.Append("to");
                chooseCities.Append(new SemanticResultKey("destination", cities));

                // Build a Grammar object from the GrammarBuilder.
                Grammar bookFlight = new Grammar(chooseCities);
                bookFlight.Name = "Book Flight";

                // Add a handler for the LoadGrammarCompleted event.
                recognizer.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
                // Attach event handlers for recognition events.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(
                    SpeechRecognizedHandler);
                recognizer.EmulateRecognizeCompleted +=
                  new EventHandler<EmulateRecognizeCompletedEventArgs>(
                    EmulateRecognizeCompletedHandler);
                // Load the grammar object to the recognizer.
                recognizer.LoadGrammarAsync(bookFlight);
            }
        }