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