Choices Constructor (GrammarBuilder[])

Constructs a new instance of Choices from one or more GrammarBuilder instances.

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

Syntax

'Declaration




Parameters

Remarks

The Choices created with this constructor defines a choice between one or more different grammars, as expressed by the GrammarBuilder arguments supplied.

These GrammarBuilder object may themselves have been constructed from Choices objects.

Because GrammarBuilder provide support for implicit conversion of Choices, SemanticResultValue, and SemanticResultKey objects to GrammarBuilder instances, by properly using casts, this constructor can also be used to create a Choices object from a list of any combination of these objects.

Example

In this example a Grammar object is created which supports two commands to change colors "Set background to [color]" and "Change background to [color]".

Two Choices objects are created -- one (bothChoice) is constructed from two GrammarBuilder objects containing an introductory phrase for a command ("Set background to" and "Change background to"), the other (colorChoice) constructed from an array of color names System.String objects.

These two Choices object are then added together (making use of implicit conversion support for the Choices object under the GrammarBuilder class).

The construction of a Choices object from GrammarBuilder parameters is highlighted.

private Grammar CreateSimpleColorGrammar1(params int[] info) {
    GrammarBuilder builder1 = "Set background to";
    GrammarBuilder builder2 = "Change background to";
    Choices bothChoice = new Choices(builder1, builder2);

    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.
        colorNameList.Add(colorName);
    }
    string[] colors = (string[])colorNameList.ToArray(typeof(string));
    Choices colorChoice = new Choices(colors);


    GrammarBuilder bothBuilders = GrammarBuilder.Add(bothChoice,(GrammarBuilder)colorChoice);
    Grammar grammar = new Grammar(bothBuilders);
    grammar.Name = "Set/Change Background to";

    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

Choices Class
Choices Members
Microsoft.Speech.Recognition Namespace
GrammarBuilder
Grammar
SemanticResultValue
SemanticResultKey