Search code examples
c#speech-to-text

How can I stop the process until I find a word in SpeechToText?


I need this function to finish when I say an specific word to later continue whith other stuff.

I'm working on c# with the System.Speech.Recognition library. Also I'm working in Spanish and I've tried recognition before and it works but finalizing with a key press the "recording.

public static void waitforstart() {
            while (true) {
                SpeechRecognitionEngine oEscucha = new SpeechRecognitionEngine();
                oEscucha.SetInputToDefaultAudioDevice();
                GrammarBuilder gr = new GrammarBuilder();
                oEscucha.LoadGrammar(new DictationGrammar());

                oEscucha.SpeechRecognized += Deteccion;
                oEscucha.RecognizeAsync(RecognizeMode.Single);

                Console.WriteLine("1");
                if (intro.IndexOf("botella", 0, StringComparison.CurrentCultureIgnoreCase) != -1) { //That chechs if "botella" is inside the text ignoring uppercase
                    break;
                }
        } }

Solution

  • public static void waitforstart() {
            while (true) {
                SpeechRecognitionEngine oEscucha = new SpeechRecognitionEngine();
                oEscucha.SetInputToDefaultAudioDevice();
                GrammarBuilder gr = new GrammarBuilder();
                oEscucha.LoadGrammar(new DictationGrammar());
    
                oEscucha.SpeechRecognized += Deteccion;
                oEscucha.Recognize();
    
                Console.WriteLine(intro);
                if (intro.IndexOf("botella", 0, StringComparison.CurrentCultureIgnoreCase) != -1) { //That chechs if "botella" is inside the text ignoring uppercase
                    break;
                }
        } }