1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | using System; using System.Speech.Recognition; using System.Speech.Synthesis; namespace SpeechRecognitionApp { class Program { static void Main(string[] args) { // Select a speech recognizer that supports English. RecognizerInfo info = null; foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) { if (ri.Culture.TwoLetterISOLanguageName.Equals("en")) { info = ri; break; } } if (info == null) return; // Create the selected recognizer. using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(info)) { // Create and load a dictation grammar. recognizer.LoadGrammar(new DictationGrammar()); // 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); // Keep the console window open. while (true) { Console.ReadLine(); } } } // Handle the SpeechRecognized event. static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { Console.WriteLine("Recognized text: " + e.Result.Text); } } } | cs |