Choices 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一组在语音识别语法约束的选择。
public ref class Choicespublic class Choicestype Choices = classPublic Class Choices- 继承
- 
				Choices
示例
以下示例为短语“将背景设置为 colorChoice”创建语音识别语法,其中 colorChoice 可以是定义的颜色之一。 GrammarBuilder用于定义语法的约束。
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 表示短语的一个组件,该短语可以具有多个值之一。 从 对象创建语音识别语法时, GrammarBuilder 请使用此类。
例如,对象 Choices 可以表示短语“将颜色更改为 colorChoice ”中的组件 colorChoice,其中 colorChoice 的可接受值为“红色”、“绿色”或“蓝色”。
注意
若要将 Choices 对象用作短语中的可选组件,请创建 Choices 对象,并将其 GrammarBuilder.GrammarBuilder(GrammarBuilder, Int32, Int32) 分别添加到 对象 minRepeat ,并将 maxRepeat 它分别设置为 0 和 1。 无论是否朗读可选组件,都可以识别包含可选组件的短语。
类Choices提供与语音识别语法规范 (SRGS) 版本 1.0 定义的 XML 元素相同的函数one-of,并且类似于 SrgsOneOf 命名空间中的 System.Speech.Recognition.SrgsGrammar 类。
有关定义语音识别语法的详细信息,请参阅 语音识别。
构造函数
| Choices() | 初始化包含空备选项集的 Choices 类的新实例。 | 
| Choices(GrammarBuilder[]) | 从包含一个或多个 Choices 对象数组初始化 GrammarBuilder 类的新实例。 | 
| Choices(String[]) | 
方法
| Add(GrammarBuilder[]) | 将包含一个或多个 GrammarBuilder 对象的数组添加到替代项组中。 | 
| Add(String[]) | 将包含一个或多个 String 对象的数组添加到替代项组中。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToGrammarBuilder() | 从 GrammarBuilder 对象返回此 Choices 对象。 | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |