Represents a list of alternative items to make up an element in a grammar.
Namespace:
System.Speech.Recognition
Assembly:
System.Speech (in System.Speech.dll)
Visual Basic (Declaration)
The Choices class is directly used only by GrammarBuilder objects.
A Choices object allows an application or developer to create a Grammar from a GrammarBuilder which can recognize audio input where one part of a phrase can have several values.
For example, a GrammarBuilder that supporting recognizing the phrase "Change color to [color]", where "[color]" can be any one of a list of values, would use an instance of Choices to define the acceptable values of "[color]".
The Choices class is analogous in its use to the SrgsOneOf member of the name space, or the one-of XML element under the Speech Recognition Grammar Specification (SRGS) name space.
The example below creates a Choices object (colorChoice) containing a list of all colors supported by the system. The Choices is then appended to the phrase "Set Background to" and a Grammar is created, which will recognize input of the form "Set background to [color]", where color could be any of the names of the members of the enumeration, such as "red", "blue", and "ActiveBorder".
private Grammar CreateSimpleColorGrammar(params int[] info) {
Choices colorChoice = new Choices(); // Associate the string
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("Set Background to");
builder1.Append(colorChoice);
Grammar grammar = new Grammar(builder1);
grammar.Name = "Set Background to";
if (info.Length >= 1) {
grammar.Priority = info[0];
}
return grammar;
}
System..::.Object
System.Speech.Recognition..::.Choices
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources