GrammarBuilder.Append Method (GrammarBuilder, Int32, Int32)

Appends an instance of GrammarBuilder to the current GrammarBuilder with minimum and maximum repetition counters.

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

Syntax

'Declaration
Public Sub Append ( _
    builder As GrammarBuilder, _
    minRepeat As Integer, _
    maxRepeat As Integer _
)
public void Append (
    GrammarBuilder builder,
    int minRepeat,
    int maxRepeat
)
public:
void Append (
    GrammarBuilder^ builder, 
    int minRepeat, 
    int maxRepeat
)
public void Append (
    GrammarBuilder builder, 
    int minRepeat, 
    int maxRepeat
)
public function Append (
    builder : GrammarBuilder, 
    minRepeat : int, 
    maxRepeat : int
)

Parameters

  • builder
    A GrammarBuilder instance containing the grammar logic to match against audio input.
  • minRepeat
    Specifies the minimum number of times the audio input matching the GrammarBuilder specified by the builder parameter can be repeated and still be successfully recognized.
  • maxRepeat
    Specifies the maximum number of times the audio input matching the GrammarBuilder specified by the builder parameter can be repeated and still be successfully recognized.

Remarks

The value of minRepeat must be greater than or equal to 0 and less than or equal to the value of maxRepeat.

Care should be taken if the GrammarBuilderspecified by builder has been constructed using any SemanticResultValue or GrammarBuilder instances.

An exception will be thrown during the use of a GrammarBuilder generated from a GrammarBuilder constructed with repeats of a defining GrammarBuilder if the repetition of the grammar logic of 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.

Similarly, an exception will be generated during the use of a Grammar generated from a GrammarBuilder constructed with repeats of a defining Grammarif the repetition of the grammar logic of that Grammar will result in more than one instance of SemanticResultKey with the same tag value and at the same level in the recognition semantic tree are created.

Example

In the example below a Grammar is built that will to support recognizing an audio input which may optionally begin with “please”, must have the input “give me”, and five inputs matching a Choices option.

For example the inputs “give me pear soap” and “please give me apple soap pear” will be matched.

To implement the Grammar, two GrammarBuilder instances are appended with minimum and maximum repeats defined:

  • The code GrammarBuilder productsGB = new GrammarBuilder((GrammarBuilder)productsChoices, 1, 5); appends grammar logic to the current GrammarBuilder (groceryGB) to match audio inputs with one to five occurrences which will satisfy a Choices (productsChoices)

  • The code groceryGB.Append("please", 0, 1); appends grammar logic to the current GrammarBuilder (groceryGB) to match audio inputs with either one or no occurrence of the word “please”.

private void groceryGrammar() {
    GrammarBuilder groceryGB = new GrammarBuilder();
    groceryGB.Append("please", 0, 1);
    groceryGB.Append("give me");
    Choices productsChoices = new Choices("apple", "pear", "banana", "apples", "pears", "bananas", "soap", "milk");
    GrammarBuilder productsGB = new GrammarBuilder((GrammarBuilder)productsChoices, 1, 5);
    groceryGB.Append( new SemanticResultKey("Products", productsGB));
    Grammar grammar = new Grammar(groceryGB);
    grammar.Enabled = true;
    grammar.Name = "Grocery Grammar";
    _recognizer.LoadGrammar(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.

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