Choices 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 Choices 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| Choices() |
初始化包含一组空替代项的类的新实例 Choices 。 |
| Choices(GrammarBuilder[]) |
从包含一个或多个Choices对象的数组初始化类的新实例GrammarBuilder。 |
| Choices(String[]) |
示例
以下示例使用 Choices 对象创建两个替代项列表。
第一个 Choices 对象是从对象数组构造的 String 。 另 Choices 一个对象是从已由强制转换隐式转换的对象数组 GrammarBuilder 构造的。
该示例使用对象 GrammarBuilder 来组合短语,使用 Choices 对象和另外两个字符串,该字符串可用于识别语音输入形式为“在 [phoneType] 手机上调用 [contactlList]”,例如“在移动电话上呼叫简”。
public GrammarBuilder ChoicesConstructor2 ()
{
GrammarBuilder gb = new GrammarBuilder ();
Choices phoneType = new Choices (new string[] {"cell", "home", "work"});
Choices contactList = new Choices (new GrammarBuilder[] {(GrammarBuilder) "Mark", (GrammarBuilder) "Jane", (GrammarBuilder) "Frank"});
gb.Append ("Call");
gb.Append (contactList);
gb.Append ("on");
gb.Append (phoneType);
gb.Append ("phone");
return gb;
}
注解
可以使用无参数构造函数(该构造函数从一组Choices对象或一组String对象返回空对象)构造GrammarBuilder对象。
由于对象GrammarBuilder支持隐式转换SemanticResultValue,SemanticResultKeyChoices因此可以使用强制转换从这些对象的数组构造 a。
Choices()
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
初始化包含一组空替代项的类的新实例 Choices 。
public:
Choices();
public Choices();
Public Sub New ()
示例
以下示例使用 Choices 和 GrammarBuilder 对象创建一个短语,该短语可用于识别语音输入,例如“在单元格上呼叫安妮”和“在他的工作电话上呼叫 James”。 该示例使用隐式转换和ChoicesString转换。GrammarBuilder
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
注解
此构造函数返回一组有效的空替代项。 可以使用任何 Add 方法添加替代项。
另请参阅
适用于
Choices(GrammarBuilder[])
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
从包含一个或多个Choices对象的数组初始化类的新实例GrammarBuilder。
public:
Choices(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);
public Choices(params System.Speech.Recognition.GrammarBuilder[] alternateChoices);
new System.Speech.Recognition.Choices : System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.Choices
Public Sub New (ParamArray alternateChoices As GrammarBuilder())
参数
- alternateChoices
- GrammarBuilder[]
包含一组替代项的数组。
示例
以下示例使用 Choices 和 GrammarBuilder 对象为短语创建一个 Grammar 短语,例如“在单元格上呼叫安妮”和“在他的工作电话上呼叫 James”。 该示例使用隐式转换和ChoicesString转换。GrammarBuilder
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
注解
每个 GrammarBuilder 选项 alternateChoices 定义一种替代方法。 如果 alternateChoices 为空数组,构造函数将返回一组空的替代项。 可以使用任何 Add 方法添加替代项。
构造函数将引发 ArgumentNullException when alternateChoicesnull 或 when any of the array elements is null.
由于该GrammarBuilder类通过使用强制转换正确提供对实例的隐式转换ChoicesSemanticResultValue和SemanticResultKey对象的GrammarBuilder支持,因此此构造函数还可用于从这些对象的任意组合的列表创建Choices对象。
另请参阅
适用于
Choices(String[])
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
- Source:
- Choices.cs
public:
Choices(... cli::array <System::String ^> ^ phrases);
public Choices(params string[] phrases);
new System.Speech.Recognition.Choices : string[] -> System.Speech.Recognition.Choices
Public Sub New (ParamArray phrases As String())
参数
- phrases
- String[]
包含一组替代项的数组。
示例
以下示例使用 Choices 和 GrammarBuilder 对象为短语创建一个 Grammar 短语,例如“在单元格上呼叫安妮”和“在他的工作电话上呼叫 James”。 该示例使用隐式转换和ChoicesString转换。GrammarBuilder
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
注解
每个 String 选项 phrases 定义一种替代方法。 语音识别引擎可以使用字符串数组中的任何一个项目来匹配语音输入。 如果 phrases 为空数组,构造函数将返回一组空的替代项。 可以使用任何 Add 方法添加替代项。
构造函数将引发 ArgumentNullException when phrasesnull 或任何数组元素。null 构造函数将引发 ArgumentException 数组中的任何元素是否为空字符串(“)。。