Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

GrammarBuilder.AppendRuleReference Method (String, String)

Appends the specified rule of a grammar definition file to the current sequence of grammar elements.

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

Syntax

'Declaration
Public Sub AppendRuleReference ( _
    path As String, _
    rule As String _
)
'Usage
Dim instance As GrammarBuilder
Dim path As String
Dim rule As String

instance.AppendRuleReference(path, rule)
public void AppendRuleReference(
    string path,
    string rule
)

Parameters

  • path
    Type: System.String
    A String containing the file path or Universal Resource Identifier (URI) of the file that describes a speech recognition grammar in a supported format.
  • rule
    Type: System.String
    The identifier of the rule to append, or a null reference (Nothing in Visual Basic) to append the default root rule of the grammar file.

Remarks

The URI provided by the path argument may be local or remote. The application must have read access to the location of specified grammar files.

You can use the use the AppendRuleReference(String) method to append a grammar file beginning with its root rule.

Examples

The following C# example creates a speech recognition grammar that uses the rule named Cities in a local SRGS file, cities.grxml. The content of the cities.grxml file appears below the C# code example.

private static Grammar CreateCitiesGrammar2()
{
  GrammarBuilder builder = new GrammarBuilder();
  builder.Append("Does");
  builder.AppendRuleReference(@"c:\temp\cities.grxml", "Cities");
  builder.Append("have a shuttle");

  Grammar citiesGrammar = new Grammar(builder);
  citiesGrammar.Name = "Cities Grammar 2";
  return citiesGrammar;
}
<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
         xmlns="http://www.w3.org/2001/06/grammar"
         tag-format="semantics/1.0" root="Main">
  
  <!-- cities.grxml: 
    Defines an SRGS grammar for requesting a flight. This grammar includes
    a Cities rule that lists the cities that can be used for departures
    and destinations. -->
  
  <rule id="Main">
    <item>
      I would like to fly from <ruleref uri="#Cities"/>
      to <ruleref uri="#Cities"/>
    </item>
  </rule>

  <rule id="Cities" scope="public">
    <one-of>
      <item> Seattle </item>
      <item> Los Angeles </item>
      <item> New York </item>
      <item> Miami </item>
    </one-of>
  </rule>
</grammar>

See Also

Reference

GrammarBuilder Class

GrammarBuilder Members

AppendRuleReference Overload

Microsoft.Speech.Recognition Namespace