Choices 类

定义

表示一组在语音识别语法约束的选择。Represents a set of alternatives in the constraints of a speech recognition grammar.

public ref class Choices
public class Choices
type Choices = class
Public Class Choices
继承
Choices

示例

下面的示例创建了 "将背景设置为colorChoice" 一词的语音识别语法, 其中colorChoice可以为定义的颜色之一。The following example creates a speech recognition grammar for the phrase, "Set background to colorChoice", where colorChoice can be one of the defined colors. GrammarBuilder用于定义语法约束。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;  
}  

注解

Choices对象表示可以具有若干值之一的短语的组件。A Choices object represents a component of a phrase that can have one of several values. 在从GrammarBuilder对象创建语音识别语法时使用此类。Use this class when creating a speech recognition grammar from a GrammarBuilder object.

例如, Choices对象可以表示短语 "将颜色更改为colorChoice" 中的组件colorChoice , 其中colorChoice可接受的值为 "red"、"绿色" 或 "蓝色"。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".

备注

若要将Choices对象用作短语中的可选组件, 请Choices创建对象GrammarBuilder.GrammarBuilder(GrammarBuilder, Int32, Int32)并将minRepeat其添加maxRepeat到对象并将设置为0和1。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.

System.Speech.Recognition.SrgsGrammar one-of SrgsOneOf 类与语音识别语法规范 (SRGS) 版本1.0 定义的 XML 元素提供相同的功能, 类似于命名空间中的类。 ChoicesThe 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 System.Speech.Recognition.SrgsGrammar namespace.

有关定义语音识别语法的详细信息, 请参阅语音识别创建 GrammarBuilder 语法For more information about defining a speech recognition grammar, see Speech Recognition and Creating GrammarBuilder Grammars.

构造函数

Choices()

初始化包含空备选项集的 Choices 类的新实例。Initializes a new instance of the Choices class that contains an empty set of alternatives.

Choices(GrammarBuilder[])

从包含一个或多个 Choices 对象数组初始化 GrammarBuilder 类的新实例。Initializes a new instance of the Choices class from an array containing one or more GrammarBuilder objects.

Choices(String[])

从包含一个或多个 Choices 对象数组初始化 String 类的新实例。Initializes a new instance of the Choices class from an array containing one or more String objects.

方法

Add(GrammarBuilder[])

将包含一个或多个 GrammarBuilder 对象的数组添加到替代项组中。Adds an array containing one or more GrammarBuilder objects to the set of alternatives.

Add(String[])

将包含一个或多个 String 对象的数组添加到替代项组中。Adds an array containing one or more String objects to the set of alternatives.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToGrammarBuilder()

GrammarBuilder 对象返回此 Choices 对象。Returns a GrammarBuilder object from this Choices object.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅