Choices 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 Choices 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| Choices() |
初始化包含空選項集合的新 Choices 類別實例。 |
| Choices(GrammarBuilder[]) |
從包含一個或多個Choices物件的陣列初始化該GrammarBuilder類別的新實例。 |
| Choices(String[]) |
範例
以下範例使用 Choices 物件來建立兩個替代方案清單。
第一個 Choices 物件由一組 String 物件陣列構成。 另一個 Choices 物件則由一組 GrammarBuilder 物件陣列構成,這些物件由 cast 隱含轉換而成。
範例中使用物件 GrammarBuilder 組合短語,利用 Choices 物件及兩串額外字串,可用來辨識語音輸入,形式為「Call [contactlList] on [phoneType] phone」,例如「Call Jane on cell phone」。
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 隱式轉換,可以用鑄造方法從這些物件的陣列構造出來。
Choices()
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
初始化包含空選項集合的新 Choices 類別實例。
public:
Choices();
public Choices();
Public Sub New ()
範例
以下範例使用 Choices 和 GrammarBuilder 物件來創造一個可用來辨識語音輸入的片語,例如「Call Anne on her cell with her cell」和「Call James」 on his work phone。 範例使用從 Choices 和 String 隱式鑄造到 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[])
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- 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 像「Call Anne on her cell cell」和「Call James on his work phone」這類片語的 for。 範例使用從 Choices 和 String 隱式鑄造到 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 in alternateChoices 都定義了一個替代方案。 若 alternateChoices 為空陣列,建構子回傳一組空的備選方案。 你可以用任何 Add 方法加入替代方案。
當 是 或 ArgumentNullException 當任一陣列元素為 alternateChoices時,建構子會拋出一個 null 。null
由於該 GrammarBuilder 類別透過正確使用 cast 隱含地將 Choices、 SemanticResultValue及 SemanticResultKey 物件轉換為 GrammarBuilder 實例,此建構子也可用來從任意組合這些物件的清單中建立 Choices 物件。
另請參閱
適用於
Choices(String[])
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- 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 物件來創造像「Call Anne on her cell cell」和「Call James on his work phone」這類片語的 a Grammar 。 範例使用從 Choices 和 String 隱式鑄造到 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 in phrases 都定義了一個替代方案。 語音辨識引擎可以使用字串陣列中的任一個項目來匹配語音輸入。 若 phrases 為空陣列,建構子回傳一組空的備選方案。 你可以用任何 Add 方法加入替代方案。
當 ArgumentNullException 是 或phrases任一陣列元素 時null,建構子會拋null出 。 若陣列中有空字串(“”),則建構子會拋出 。ArgumentException