Compartilhar via


Note

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

Choices Class

Represents a list of alternative items to make up an element in a grammar.

Inheritance Hierarchy

System.Object
  Microsoft.Speech.Recognition.Choices

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

Syntax

'Declaration
Public Class Choices
'Usage
Dim instance As Choices
public class Choices

Remarks

A Choices object represents a component of a phrase that can have one of several values. Use this class when creating a speech recognition grammar from a GrammarBuilder object.

For example, a Choices object could represent the component colorChoice in the phrase, "Change the color to colorChoice", where acceptable values for colorChoice are “red”, or “green”, or “blue”.

Note

To use a Choices object as an optional component in a phrase, create the Choices object and add it to a GrammarBuilder.GrammarBuilder(GrammarBuilder, Int32, Int32) object with minRepeat and maxRepeat set to 0 and 1, respectively. Phrases containing optional components can be recognized whether or not the optional component is spoken.

The Choices class serves the same function as the one-of XML element defined by the Speech Recognition Grammar Specification (SRGS) Version 1.0, and is similar to the SrgsOneOf class in the Microsoft.Speech.Recognition.SrgsGrammar namespace.

Examples

The following example creates a speech recognition grammar for the phrase, "Set background to colorChoice", where colorChoice can be one of the defined colors. The GrammarBuilder is used to define the constraints for the grammar.

private Grammar CreateColorGrammar()
{

  // Create a Choices object that contains a set of alternative colors.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
  colorChoice.Add(new string[] {"cyan", "yellow", "magenta"});

  // Construct the phrase.
  GrammarBuilder builder = new GrammarBuilder("Set background to");
  builder.Append(colorChoice);

  // Create a grammar for the phrase.
  Grammar colorGrammar = new Grammar(builder);
  colorGrammar.Name = "SetBackground";

  return colorGrammar;
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Choices Members

Microsoft.Speech.Recognition Namespace

Microsoft.Speech.Recognition.SrgsGrammar

GrammarBuilder

Grammar

Other Resources

Speech Recognition Grammar Specification (SRGS) Version 1.0