Created
March 24, 2023 19:35
-
-
Save MuhammadSulaiman001/f71e8ad7dfeb47774e03170de7cb83ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Speech.Recognition; | |
namespace ConsoleApp | |
{ | |
internal static class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
// Create an in-process speech recognizer for the en-US locale. | |
using var recognizer = | |
new SpeechRecognitionEngine( | |
new System.Globalization.CultureInfo("en-US") | |
); | |
// Create and load a dictation grammar. | |
recognizer.LoadGrammar(new DictationGrammar()); | |
// Add a handler for the speech recognized event. | |
recognizer.SpeechRecognized += 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment