Share via


Note

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

SrgsOneOf Constructor (SrgsItem[])

Initializes a new instance of the SrgsOneOf class, specifying one or more alternative items in the passed SrgsItem array.

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

Syntax

'Declaration
Public Sub New ( _
    ParamArray items As SrgsItem() _
)
'Usage
Dim items As SrgsItem()

Dim instance As New SrgsOneOf(items)
public SrgsOneOf(
    params SrgsItem[] items
)

Parameters

  • items
    Type: []
    The alternative items to add.

Exceptions

Exception Condition
ArgumentNullException

items is a null reference (Nothing in Visual Basic).

Any element in the items array is a null reference (Nothing in Visual Basic).

Examples

The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country that has won the World Cup. It creates a public rule named WorldCupWinner. It then creates two SrgsRule objects using SrgsOneOf objects that contain arrays of new SrgsItem objects. To see the grammar that this example generates, see SrgsRule.

 public void WorldSoccerWinners ()
{

  // Create an SrgsDocument, create a new rule
  // and set its scope to public.
  SrgsDocument document = new SrgsDocument();
  SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
  winnerRule.Scope = SrgsRuleScope.Public;

  // Add the introduction.
  winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));

  // Create the rule for the European nations.
  SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"),new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"),new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
  SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

  // Add references to winnerRule for ruleEurope and ruleSAmerica.
  winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem 
    (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

  // Add all the rules to the document and make winnerRule 
  // the root rule of the document.
  document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  document.Root = winnerRule;
}

See Also

Reference

SrgsOneOf Class

SrgsOneOf Members

SrgsOneOf Overload

Microsoft.Speech.Recognition.SrgsGrammar Namespace

Other Resources

Create Grammars Using SrgsGrammar (Microsoft.Speech)