Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MuhammadSulaiman001/f71e8ad7dfeb47774e03170de7cb83ce to your computer and use it in GitHub Desktop.
Save MuhammadSulaiman001/f71e8ad7dfeb47774e03170de7cb83ce to your computer and use it in GitHub Desktop.
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