.NET Framework

SpeechRecognitionEngine class to recognize speech

LoadGrammar: ParametersDetails
grammarThe grammar to load. For example, a DictationGrammar object to allow free text dictation.
RecognizeAsync: ParametersDetails
modeThe RecognizeMode for the current recognition: Single for just one recognition, Multiple to allow multiple.
GrammarBuilder.Append: ParametersDetails
choicesAppends some choices to the grammar builder. This means that, when the user inputs speech, the recognizer can follow different “branches” from a grammar.
Choices constructor: ParametersDetails
choicesAn array of choices for the grammar builder. See GrammarBuilder.Append.
Grammar constructor: ParameterDetails
builderThe GrammarBuilder to construct a Grammar from.

Asynchronously recognizing speech based on a restricted set of phrases

SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine();
GrammarBuilder builder = new GrammarBuilder();
builder.Append(new Choices("I am", "You are", "He is", "She is", "We are", "They are"));
builder.Append(new Choices("friendly", "unfriendly"));
recognitionEngine.LoadGrammar(new Grammar(builder));
recognitionEngine.SpeechRecognized += delegate(object sender, SpeechRecognizedEventArgs e)
{
 Console.WriteLine("You said: {0}", e.Result.Text);
};
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);

Asynchronously recognizing speech for free text dictation

using System.Speech.Recognition;
// ...
SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine();
recognitionEngine.LoadGrammar(new DictationGrammar());
recognitionEngine.SpeechRecognized += delegate(object sender, SpeechRecognizedEventArgs e)
{
 Console.WriteLine("You said: {0}", e.Result.Text);
};
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);

Source
.NET Framework Notes for Professionals book
Tags

Ahmed Mohamed Abd ElMajeed

Web developer and Server Administrator, Founder of Akwad web School and Programmer Notes.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close

Adblock Detected

Please consider supporting us by disabling your ad blocker