GrammarBuilder.Add Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a new GrammarBuilder that contains a sequence of two grammar elements.
Overloads
Add(Choices, GrammarBuilder) |
Creates a new GrammarBuilder that contains a Choices object followed by a GrammarBuilder object. |
Add(GrammarBuilder, Choices) |
Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a Choices object. |
Add(GrammarBuilder, GrammarBuilder) |
Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects. |
Add(GrammarBuilder, String) |
Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a phrase. |
Add(String, GrammarBuilder) |
Creates a new GrammarBuilder that contains a phrase followed by a GrammarBuilder object. |
Remarks
The static Add methods provide another mechanism by which you can combine various types to create diversity and flexibility in grammars built with GrammarBuilder. These methods correspond to the static Addition methods, which are also defined on the GrammarBuilder class. The order of the parameters determines the order of the elements in the new GrammarBuilder.
A GrammarBuilder can also be obtained from Choices, SemanticResultKey, SemanticResultValue, and String objects. For more information, see the Implicit and Addition operators.
Important
The speech recognizer can throw an exception when using a speech recognition grammar that contains duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the value of the same semantic element.
For more information about building and using speech recognition grammars, see Speech Recognition.
Add(Choices, GrammarBuilder)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Creates a new GrammarBuilder that contains a Choices object followed by a GrammarBuilder object.
public:
static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::Choices ^ choices, System::Speech::Recognition::GrammarBuilder ^ builder);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.Choices choices, System.Speech.Recognition.GrammarBuilder builder);
static member Add : System.Speech.Recognition.Choices * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (choices As Choices, builder As GrammarBuilder) As GrammarBuilder
Parameters
- choices
- Choices
The first grammar element, which represents a set of alternatives.
- builder
- GrammarBuilder
The second grammar element.
Returns
A GrammarBuilder for the sequence of the choices
element followed by the builder
element.
Remarks
GrammarBuilder supports implicit conversions from the following classes:
This method accepts the objects listed above for the builder
parameter.
For more information, see the Implicit and Addition operators.
Important
When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. The speech recognizer can throw an exception if it encounters these circumstances. For more information about building a speech recognition grammar that contains semantic information, see Add Semantics to a GrammarBuilder Grammar.
See also
Applies to
Add(GrammarBuilder, Choices)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a Choices object.
public:
static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder, System::Speech::Recognition::Choices ^ choices);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder, System.Speech.Recognition.Choices choices);
static member Add : System.Speech.Recognition.GrammarBuilder * System.Speech.Recognition.Choices -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder As GrammarBuilder, choices As Choices) As GrammarBuilder
Parameters
- builder
- GrammarBuilder
The first grammar element.
- choices
- Choices
The second grammar element, which represents a set of alternatives.
Returns
A GrammarBuilder for the sequence of the builder
element followed by the choices
element.
Examples
The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. The explicit cast operators in the calls to the Add methods are optional.
private Grammar CreateColorGrammar()
{
// Create a set of color choices.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
// Create grammar builders for the two versions of the phrase.
GrammarBuilder makePhrase =
GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
GrammarBuilder setPhrase =
GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);
// Create a Choices for the two alternative phrases, convert the Choices
// to a GrammarBuilder, and construct the grammar from the result.
Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);
Grammar grammar = new Grammar(bothPhrases);
grammar.Name = "backgroundColor";
return grammar;
}
Remarks
GrammarBuilder supports implicit conversions from the following classes:
This method accepts the objects listed above for the builder
parameter.
For more information, see the Implicit and Addition operators.
Important
When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances with other grammar elements, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. The speech recognizer can throw an exception if it encounters these circumstances.
See also
Applies to
Add(GrammarBuilder, GrammarBuilder)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects.
public:
static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder1, System::Speech::Recognition::GrammarBuilder ^ builder2);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder1, System.Speech.Recognition.GrammarBuilder builder2);
static member Add : System.Speech.Recognition.GrammarBuilder * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder1 As GrammarBuilder, builder2 As GrammarBuilder) As GrammarBuilder
Parameters
- builder1
- GrammarBuilder
The first grammar element.
- builder2
- GrammarBuilder
The second grammar element.
Returns
A GrammarBuilder for the sequence of the builder1
element followed by the builder2
element.
Examples
The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. The explicit cast operators in the calls to the Add methods are optional.
private Grammar CreateColorGrammar()
{
// Create a set of color choices.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
// Create grammar builders for the two versions of the phrase.
GrammarBuilder makePhrase =
GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
GrammarBuilder setPhrase =
GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);
// Create a Choices for the two alternative phrases, convert the Choices
// to a GrammarBuilder, and construct the grammar from the result.
Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);
Grammar grammar = new Grammar(bothPhrases);
grammar.Name = "backgroundColor";
return grammar;
}
Remarks
GrammarBuilder supports implicit conversions from the following classes:
This method accepts the objects listed above for the builder1
or builder2
parameter.
For more information, see the Implicit and Addition operators.
Important
When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances with other grammar elements, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. The speech recognizer can throw an exception if it encounters these circumstances.
See also
Applies to
Add(GrammarBuilder, String)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a phrase.
public:
static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder, System::String ^ phrase);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder, string phrase);
static member Add : System.Speech.Recognition.GrammarBuilder * string -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder As GrammarBuilder, phrase As String) As GrammarBuilder
Parameters
- builder
- GrammarBuilder
The first grammar element.
- phrase
- String
The second grammar element, which represents a sequence of words.
Returns
A GrammarBuilder for the sequence of the builder
element followed by the phrase
element.
Examples
The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. The explicit cast operators in the calls to the Add methods are optional.
private Grammar CreateColorGrammar()
{
// Create a set of color choices.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
// Create grammar builders for the two versions of the phrase.
GrammarBuilder makePhrase =
GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
GrammarBuilder setPhrase =
GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);
// Create a Choices for the two alternative phrases, convert the Choices
// to a GrammarBuilder, and construct the grammar from the result.
Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);
Grammar grammar = new Grammar(bothPhrases);
grammar.Name = "backgroundColor";
return grammar;
}
Remarks
GrammarBuilder supports implicit conversions from the following classes:
This method accepts the objects listed above for the builder
parameter.
For more information, see the Implicit and Addition operators.
See also
Applies to
Add(String, GrammarBuilder)
- Source:
- GrammarBuilder.cs
- Source:
- GrammarBuilder.cs
Creates a new GrammarBuilder that contains a phrase followed by a GrammarBuilder object.
public:
static System::Speech::Recognition::GrammarBuilder ^ Add(System::String ^ phrase, System::Speech::Recognition::GrammarBuilder ^ builder);
public static System.Speech.Recognition.GrammarBuilder Add (string phrase, System.Speech.Recognition.GrammarBuilder builder);
static member Add : string * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (phrase As String, builder As GrammarBuilder) As GrammarBuilder
Parameters
- phrase
- String
The first grammar element, which represents a sequence of words.
- builder
- GrammarBuilder
The second grammar element.
Returns
A GrammarBuilder for the sequence of the phrase
element followed by the builder
element.
Examples
The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. The explicit cast operators in the calls to the Add methods are optional.
private Grammar CreateColorGrammar()
{
// Create a set of color choices.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
// Create grammar builders for the two versions of the phrase.
GrammarBuilder makePhrase =
GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
GrammarBuilder setPhrase =
GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);
// Create a Choices for the two alternative phrases, convert the Choices
// to a GrammarBuilder, and construct the grammar from the result.
Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);
Grammar grammar = new Grammar(bothPhrases);
grammar.Name = "backgroundColor";
return grammar;
}
Remarks
GrammarBuilder supports implicit conversions from the following classes:
This method accepts the objects listed above for the builder
parameter.
For more information, see the Implicit and Addition operators.