GrammarBuilder Constructor (SemanticResultValue)

Constructs a GrammarBuilder object from a phrase expressed as a SemanticResultValue instance.

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

Syntax

'Declaration
Public Sub New ( _
    value As SemanticResultValue _
)
public GrammarBuilder (
    SemanticResultValue value
)
public:
GrammarBuilder (
    SemanticResultValue^ value
)
public GrammarBuilder (
    SemanticResultValue value
)
public function GrammarBuilder (
    value : SemanticResultValue
)

Parameters

Remarks

Care should be taken with GrammarBuilder instances constructed using a SemanticResultValue instance.

An exception will be thrown during the use of a Grammar generated from a GrammarBuilder if that GrammarBuilder include instances of SemanticResultValue that would require repeated modifications of the Value property of the one of the SemanticValue objects returned by a recognition operation.

Example

The code sample below constructs a Grammar which recognizes either of two phrases: "Make background [color]" or "Configure background as [color]" using a explicit creation of and implicit conversion to GrammarBuilder instances.

The explicit construction of a GrammarBuilder object using a Choices instance is highlighted in the example code below.

private Grammar CreateGrammarBuilderRGBSemantics2(params int[] info) {
    //Create a set of choices, each a lookup from a color name to RGB
    //Choices constructors do not take SematicResultValue, so cast SematicResultValue to GramarBuilder
    Choices colorChoice = new Choices();
    //Construct new instance of GrammarBuilder from SemanticResultValues
    //Obtained from the system colors and add them to the colorChoice.
    foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) {
        SemanticResultValue choiceResultValue =
            new SemanticResultValue(colorName, Color.FromName(colorName).ToARGB());
        GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue);
        colorChoice.Add(resultValueBuilder);
    }
    SemanticResultKey choiceResultKey = new SemanticResultKey("RGB", colorChoice);
    GrammarBuilder choiceBuilder = new GrammarBuilder(choiceResultKey);
    //Create two intermediate grammars with introductory phrase and the color choice
    GrammarBuilder makeBackgroundBuilder = "Make background";
    makeBackgroundBuilder.Append(choiceBuilder);

    GrammarBuilder configureBackgroundBuilder = new GrammarBuilder("Configure background as");
    configureBackgroundBuilder.Append(new SemanticResultKey("RGB", colorChoice));

    Choices bothChoices = new Choices(makeBackgroundBuilder, configureBackgroundBuilder);
    GrammarBuilder bothBuilder = new GrammarBuilder(bothChoices);
    Grammar grammar = new Grammar(bothBuilder);
    grammar.Name = "Make Background /Configure background as";
    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

GrammarBuilder Class
GrammarBuilder Members
Microsoft.Speech.Recognition Namespace