Grammar Constructor (GrammarBuilder)
Constructs a Grammar object from a valid GrammarBuilder instance
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Parameters
- builder
A valid GrammarBuilder defining a grammar to be used by a recognition engine.
Example
The example below shows a method which creates a grammar used to change background colors by speech recognition.
The grammar supports a choice of two different specification phrases: "Background set to {color value}" of "Background should be {color value}".
private Grammar CreateChangeColorGrammar (params int[] info) {
Choices colorChoice = new Choices(); // Associate the color string name with the system color object.
System.Collections.ArrayList colorNameList = new System.Collections.ArrayList();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) {
// Associate the string name of the color with each item.
colorChoice.Add(colorName);
}
GrammarBuilder builder1 = new GrammarBuilder();
GrammarBuilder builder2 = new GrammarBuilder();
builder1.Append("Background set to");
builder1.Append(colorChoice);
builder2.Append("Background should be");
builder2.Append(colorChoice);
GrammarBuilder builderBoth = new GrammarBuilder(new Choices(builder1, builder2));
Grammar grammar = new Grammar(builderBoth);
grammar.Name = "Change Background Color"
if (info.Length >= 1) {
grammar.Priority = info[0];
}
return grammar;
}
Platforms
Development Platforms
Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition
Target Platforms
See Also
Reference
Grammar Class
Grammar Members
Microsoft.Speech.Recognition Namespace
GrammarBuilder
SpeechRecognizer
SpeechRecognitionEngine
Grammar Constructor