語言

Choices 類別

定義

代表語音辨識文法限制下的一組替代方案。

public ref class Choices
public class Choices
type Choices = class
Public Class Choices
繼承
Choices

範例

以下範例為短語「Set background to 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」。

Note

若要將物件作為片語中的可選元件使用 Choices ,請建立該 Choices 物件並將其加入 GrammarBuilder.GrammarBuilder(GrammarBuilder, Int32, Int32) 一個分別為 minRepeatmaxRepeat 和 為 0 和 1 的物件中。 包含可選成分的片語無論是否被口語,都能被辨識。

此Choices類別的功能與one-of語音辨識文法規範(SRGS)版本 1.0 所定義的 XML 元素相同,且與SrgsOneOf命名空間中的System.Speech.Recognition.SrgsGrammar類別相似。

欲了解更多關於定義語音辨識文法的資訊,請參閱 語音辨識。

建構函式

名稱 Description
Choices()

初始化包含空選項集合的新 Choices 類別實例。

Choices(GrammarBuilder[])

從包含一個或多個Choices物件的陣列初始化該GrammarBuilder類別的新實例。

Choices(String[])

從包含一個或多個Choices物件的陣列初始化該String類別的新實例。

方法

名稱 Description
Add(GrammarBuilder[])

將包含一個或多個 GrammarBuilder 物件的陣列加入選項集合。

Add(String[])

將包含一個或多個 String 物件的陣列加入選項集合。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToGrammarBuilder()

從該GrammarBuilder物件回傳一個Choices物件。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱