text
stringlengths
0
13.4k
private IUserProvider userProvider;
public void PrintAllUsers()
{
foreach (User user in this.userProvider.GetAllUsers())
{
Console.WriteLine(user);
}
}
}
}
This is a type that has a dependency on an IUserProvider, which could be defined anywhere. Like the previous
example, all that matters is that the application knows where to look for the matching export (via the
ComposablePartCatalogs it creates).
GoalKicker.com – .NET Framework Notes for Professionals
79
Chapter 21: SpeechRecognitionEngine class
to recognize speech
LoadGrammar: Parameters
grammar
Details
The grammar to load. For example, a DictationGrammar object to allow free
text dictation.
RecognizeAsync: Parameters
Details
mode
The RecognizeMode for the current recognition: Single for just one
recognition, Multiple to allow multiple.
GrammarBuilder.Append: Parameters Details
choices
Appends 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: Parameters
Details
choices
An array of choices for the grammar builder. See GrammarBuilder.Append.
Grammar constructor: Parameter
Details
builder
The GrammarBuilder to construct a Grammar from.
Section 21.1: 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);
Section 21.2: 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);
GoalKicker.com – .NET Framework Notes for Professionals
80