Share via


Note

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

Grammar.Name Property

Gets or sets the name of a Grammar object.

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

Syntax

'Declaration
Public Property Name As String
    Get
    Set
'Usage
Dim instance As Grammar
Dim value As String

value = instance.Name

instance.Name = value
public string Name { get; set; }

Property Value

Type: System.String
Returns user friendly-name of an instance of Grammar. If it is not set, returns a null reference (Nothing in Visual Basic).

Remarks

Thoughtful use of grammar names can make code maintenance easier and user interfaces more robust.

Examples

The example below shows test cases for functionality based on SubsetMatchingMode. Each Name identifies the functionality being tested.

private Grammar CreateExact(params int[] info) 
{
  GrammarBuilder gb = new GrammarBuilder("A First Word");
  gb.Append("A Second Word");
  gb.Append("A Third Word");
  
  Utils.WriteGrammarBuilderToFile(gb, "Exact.xml");
  Grammar grammar = new Grammar(gb);
  grammar.Name = "Exact";
  return grammar;
}

private Grammar CreateOrderedSubset(params int[] info) 
{
  GrammarBuilder gb 
    = new GrammarBuilder("A First Word", 
                SubsetMatchingMode.OrderedSubset);
  gb.Append("A Second Word", 
         SubsetMatchingMode.OrderedSubset);
  gb.Append("A Third Word", 
         SubsetMatchingMode.OrderedSubset);
  Utils.WriteGrammarBuilderToFile(gb, "OrderedSubset.xml");
  Grammar grammar = new Grammar(gb);
  grammar.Name = "OrderedSubset";
  return grammar;
}

private Grammar CreateOrderedSubsetContentRequired(params int[] info) 
{
  GrammarBuilder gb 
    = new GrammarBuilder("A First Word", 
                .SubsetMatchingMode.OrderedSubsetContentRequired);
  
  gb.Append("A Second Word", 
         SubsetMatchingMode.OrderedSubsetContentRequired);
  gb.Append("A Third Word", 
         SubsetMatchingMode.OrderedSubsetContentRequired);
  
  Utils.WriteGrammarBuilderToFile(gb, "OrderedSubsetContentRequired.xml");
  Grammar grammar = new Grammar(gb);
  grammar.Name = "OrderedSubsetContentRequired";
  return grammar;
}


private Grammar CreateSubsequence(params int[] info) 
{
  GrammarBuilder gb 
    = new GrammarBuilder("A First Word", 
                .SubsetMatchingMode.Subsequence);
  gb.Append("A Second Word", 
         SubsetMatchingMode.Subsequence);
  gb.Append("A Third Word", 
         SubsetMatchingMode.Subsequence);
  Utils.WriteGrammarBuilderToFile(gb, "Subsequence.xml");
  Grammar grammar = new Grammar(gb);
  grammar.Name = "Subsequence";
  return grammar;
}

private Grammar CreateSubsequenceContentRequired(params int[] info) 
{
  GrammarBuilder gb 
    = new GrammarBuilder("A First Word", 
                SubsetMatchingMode.SubsequenceContentRequired);
  gb.Append("A Second Word", 
         SubsetMatchingMode.SubsequenceContentRequired);
  gb.Append("A Third Word", 
         SubsetMatchingMode.SubsequenceContentRequired);
  
  Utils.WriteGrammarBuilderToFile(gb, "SubsequenceContentRequired.xml");
  Grammar grammar = new Grammar(gb);
  grammar.Name = "SubsequenceContentRequired";
  return grammar;
}

See Also

Reference

Grammar Class

Grammar Members

Microsoft.Speech.Recognition Namespace