共用方式為


GrammarBuilder.Add 方法

定義

建立新的GrammarBuilder,其中包含兩個文法項目的序列。

多載

Add(Choices, GrammarBuilder)

建立新的 GrammarBuilder,其中包含 Choices 物件,後面緊接著 GrammarBuilder 物件。

Add(GrammarBuilder, Choices)

建立新的 GrammarBuilder,其中包含 GrammarBuilder 物件,後面緊接著 Choices 物件。

Add(GrammarBuilder, GrammarBuilder)

建立新的GrammarBuilder,其中包含兩個 GrammarBuilder物件的序列。

Add(GrammarBuilder, String)

建立新的 GrammarBuilder,其中包含後面接著片語的 GrammarBuilder 物件。

Add(String, GrammarBuilder)

建立新的 GrammarBuilder,其中包含後面接著 GrammarBuilder 物件的片語。

備註

靜態 Add 方法提供另一種機制,可讓您結合各種類型,以在建 GrammarBuilder 置的文法中建立多樣性和彈性。 這些方法會對應至類別上 GrammarBuilder 也定義的靜態 Addition 方法。 參數的順序會決定新 GrammarBuilder 中專案的順序。

GrammarBuilder也可以從 ChoicesSemanticResultKeySemanticResultValueString物件取得 。 如需詳細資訊,請參閱 ImplicitAddition 運算子。

重要

使用包含相同索引鍵名稱的重複語意元素的語音辨識文法,或多個可重複修改相同語意元素值的語意元素時,語音辨識器可能會擲回例外狀況。

如需建置和使用語音辨識文法的詳細資訊,請參閱 語音辨識

Add(Choices, GrammarBuilder)

來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs

建立新的 GrammarBuilder,其中包含 Choices 物件,後面緊接著 GrammarBuilder 物件。

public:
 static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::Choices ^ choices, System::Speech::Recognition::GrammarBuilder ^ builder);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.Choices choices, System.Speech.Recognition.GrammarBuilder builder);
static member Add : System.Speech.Recognition.Choices * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (choices As Choices, builder As GrammarBuilder) As GrammarBuilder

參數

choices
Choices

第一個文法項目,代表一組替代項目。

builder
GrammarBuilder

第二個文法項目。

傳回

GrammarBuilder,適用於 choices 項目後面緊接著 builder 項目的序列。

備註

GrammarBuilder 支援下列類別的隱含轉換:

這個方法會接受上面所列 builder 的 參數物件。

如需詳細資訊,請參閱 ImplicitAddition 運算子。

重要

當您結合 Choices 包含 或 SemanticResultKey 實例的 和 GrammarBuilder 物件 SemanticResultValue 時,請務必避免建立具有相同索引鍵名稱的重複語意專案,或多個可以重複修改 Value 物件屬性的 SemanticValue 語意專案。 如果遇到這些情況,語音辨識器可能會擲回例外狀況。 如需建置包含語意資訊之語音辨識文法的詳細資訊,請參閱 將語意新增至 GrammarBuilder 文法

另請參閱

適用於

Add(GrammarBuilder, Choices)

來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs

建立新的 GrammarBuilder,其中包含 GrammarBuilder 物件,後面緊接著 Choices 物件。

public:
 static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder, System::Speech::Recognition::Choices ^ choices);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder, System.Speech.Recognition.Choices choices);
static member Add : System.Speech.Recognition.GrammarBuilder * System.Speech.Recognition.Choices -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder As GrammarBuilder, choices As Choices) As GrammarBuilder

參數

builder
GrammarBuilder

第一個文法項目。

choices
Choices

第二個文法項目,這表示一組替代項目。

傳回

GrammarBuilder,適用於 builder 項目後面緊接著 choices 項目的序列。

範例

下列範例會建立語音辨識文法,以辨識兩個片語「製作背景 色彩」和「將背景設定為 色彩」,其中從一組色彩中選取 色彩 。 各種類型可用來建置最終文法,例如 StringChoices 、 和 GrammarBuilder 物件。 呼叫 Add 方法中的明確轉換運算子是選擇性的。

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase =
    GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
  GrammarBuilder setPhrase =
    GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
  GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);

  Grammar grammar = new Grammar(bothPhrases);
  grammar.Name = "backgroundColor";
  return grammar;
}

備註

GrammarBuilder 支援下列類別的隱含轉換:

這個方法會接受上面所列 builder 的 參數物件。

如需詳細資訊,請參閱 ImplicitAddition 運算子。

重要

當您結合 Choices 包含 或 SemanticResultKey 實例的 和 GrammarBuilder 物件 SemanticResultValue 與其他文法元素時,請務必避免建立具有相同索引鍵名稱的重複語意專案,或多個可重複修改 Value 物件屬性的 SemanticValue 語意專案。 如果遇到這些情況,語音辨識器可能會擲回例外狀況。

另請參閱

適用於

Add(GrammarBuilder, GrammarBuilder)

來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs

建立新的GrammarBuilder,其中包含兩個 GrammarBuilder物件的序列。

public:
 static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder1, System::Speech::Recognition::GrammarBuilder ^ builder2);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder1, System.Speech.Recognition.GrammarBuilder builder2);
static member Add : System.Speech.Recognition.GrammarBuilder * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder1 As GrammarBuilder, builder2 As GrammarBuilder) As GrammarBuilder

參數

builder1
GrammarBuilder

第一個文法項目。

builder2
GrammarBuilder

第二個文法項目。

傳回

GrammarBuilder,適用於 builder1 項目後面緊接著 builder2 項目的序列。

範例

下列範例會建立語音辨識文法,以辨識兩個片語「製作背景 色彩」和「將背景設定為 色彩」,其中從一組色彩中選取 色彩 。 各種類型可用來建置最終文法,例如 StringChoices 、 和 GrammarBuilder 物件。 呼叫 Add 方法中的明確轉換運算子是選擇性的。

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase =
    GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
  GrammarBuilder setPhrase =
    GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
  GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);

  Grammar grammar = new Grammar(bothPhrases);
  grammar.Name = "backgroundColor";
  return grammar;
}

備註

GrammarBuilder 支援下列類別的隱含轉換:

這個方法會接受以上針對 builder1builder2 參數列出的物件。

如需詳細資訊,請參閱 ImplicitAddition 運算子。

重要

當您結合 Choices 包含 或 SemanticResultKey 實例的 和 GrammarBuilder 物件 SemanticResultValue 與其他文法元素時,請務必避免建立具有相同索引鍵名稱的重複語意專案,或多個可重複修改 Value 物件屬性的 SemanticValue 語意專案。 如果遇到這些情況,語音辨識器可能會擲回例外狀況。

另請參閱

適用於

Add(GrammarBuilder, String)

來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs

建立新的 GrammarBuilder,其中包含後面接著片語的 GrammarBuilder 物件。

public:
 static System::Speech::Recognition::GrammarBuilder ^ Add(System::Speech::Recognition::GrammarBuilder ^ builder, System::String ^ phrase);
public static System.Speech.Recognition.GrammarBuilder Add (System.Speech.Recognition.GrammarBuilder builder, string phrase);
static member Add : System.Speech.Recognition.GrammarBuilder * string -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (builder As GrammarBuilder, phrase As String) As GrammarBuilder

參數

builder
GrammarBuilder

第一個文法項目。

phrase
String

第二個文法項目,這表示文字的序列。

傳回

GrammarBuilder,適用於 builder 項目後面緊接著 phrase 項目的序列。

範例

下列範例會建立語音辨識文法,以辨識兩個片語「製作背景 色彩」和「將背景設定為 色彩」,其中從一組色彩中選取 色彩 。 各種類型可用來建置最終文法,例如 StringChoices 、 和 GrammarBuilder 物件。 呼叫 Add 方法中的明確轉換運算子是選擇性的。

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase =
    GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
  GrammarBuilder setPhrase =
    GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
  GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);

  Grammar grammar = new Grammar(bothPhrases);
  grammar.Name = "backgroundColor";
  return grammar;
}

備註

GrammarBuilder 支援下列類別的隱含轉換:

這個方法會接受上面所列 builder 的 參數物件。

如需詳細資訊,請參閱 ImplicitAddition 運算子。

另請參閱

適用於

Add(String, GrammarBuilder)

來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs
來源:
GrammarBuilder.cs

建立新的 GrammarBuilder,其中包含後面接著 GrammarBuilder 物件的片語。

public:
 static System::Speech::Recognition::GrammarBuilder ^ Add(System::String ^ phrase, System::Speech::Recognition::GrammarBuilder ^ builder);
public static System.Speech.Recognition.GrammarBuilder Add (string phrase, System.Speech.Recognition.GrammarBuilder builder);
static member Add : string * System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.GrammarBuilder
Public Shared Function Add (phrase As String, builder As GrammarBuilder) As GrammarBuilder

參數

phrase
String

第一個文法項目,這表示文字的序列。

builder
GrammarBuilder

第二個文法項目。

傳回

GrammarBuilder,適用於 phrase 項目後面緊接著 builder 項目的序列。

範例

下列範例會建立語音辨識文法,以辨識兩個片語「製作背景 色彩」和「將背景設定為 色彩」,其中從一組色彩中選取 色彩 。 各種類型可用來建置最終文法,例如 StringChoices 、 和 GrammarBuilder 物件。 呼叫 Add 方法中的明確轉換運算子是選擇性的。

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase =
    GrammarBuilder.Add((GrammarBuilder)"Make background", colorChoice);
  GrammarBuilder setPhrase =
    GrammarBuilder.Add("Set background to", (GrammarBuilder)colorChoice);

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
  GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);

  Grammar grammar = new Grammar(bothPhrases);
  grammar.Name = "backgroundColor";
  return grammar;
}

備註

GrammarBuilder 支援下列類別的隱含轉換:

這個方法會接受上面所列 builder 的 參數物件。

如需詳細資訊,請參閱 ImplicitAddition 運算子。

另請參閱

適用於