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)具有和minRepeat``maxRepeat
设置为 0 和 1 的对象。 可以识别包含可选组件的短语,无论是否说出可选组件。
该 Choices 类提供与 one-of
语音识别语法规范定义的 XML 元素相同的函数 , (SRGS) 版本 1.0 ,并且类似于 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) |