Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 GrammarBuilder Constructor (String)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
GrammarBuilder Constructor (String)

Constructs a GrammarBuilder object from a phrase expressed as a [System.String] instance.

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
Visual Basic (Declaration)
Public Sub New ( _
    phrase As String _
)
Visual Basic (Usage)
Dim phrase As String

Dim instance As New GrammarBuilder(phrase)
C#
public GrammarBuilder(
    string phrase
)
Visual C++
public:
GrammarBuilder(
    String^ phrase
)
JScript
public function GrammarBuilder(
    phrase : String
)

Parameters

phrase
Type: System..::.String
A valid [System.String] instance containing a phrase to be used to construct a new instance of GrammarBuilder.

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 from a [System.String] instance is highlighted in the example code below.

private Grammar CreateGrammarBuilderRGBSemantics(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();
    foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) {
        colorChoice.Add((GrammarBuilder)
                                (new SemanticResultValue(colorName, Color.FromName(colorName).ToARGB())));
    }

    GrammarBuilder choiceBuilder = new SemanticResultKey("RGB", colorChoice);
    //Create two intermediate grammars with introductory phrase and the color choice
    GrammarBuilder makeBackgroundBuilder = "Make background";
    //Uses implicit conversion of SystemString to GrammarBuilder
    makeBackgroundBuilder.Append(choiceBuilder);
    GrammarBuilder configureBackgroundBuilder = new GrammarBuilder("Configure background as");
//Construct GrammarBuilder from string.
    configureBackgroundBuilder.Append(new SemanticResultKey("RGB", colorChoice));

    //Create the final grammar, which recognizes either intermediate grammar
    Grammar grammar = new Grammar(new Choices(makeBackgroundBuilder, configureBackgroundBuilder));
    /
    grammar.Name = "Make Background /Configure background as";

    return grammar;
}

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker