Choices Class

Represents a list of alternative items to make up an element in a grammar.

Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)


<DebuggerDisplayAttribute("{_oneOf.DebugSummary}")> _
Public Class Choices
public class Choices
public ref class Choices
/** @attribute DebuggerDisplayAttribute("{_oneOf.DebugSummary}") */ 
public class Choices
public class Choices


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.

Inheritance Hierarchy



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.
    GrammarBuilder builder1 = new GrammarBuilder("Set Background to");
    Grammar grammar = new Grammar(builder1);
    grammar.Name = "Set Background to";
    if (info.Length >= 1) {
        grammar.Priority = info[0];
    return grammar;

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.


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


Choices Members
Microsoft.Speech.Recognition Namespace

Other Resources