共用方式為


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所建置的文法中建立多樣性和彈性。 這些方法會對應至靜態 Addition 方法,這些方法也會定義於 GrammarBuilder 類別上。 參數的順序會決定新 GrammarBuilder中專案的順序。

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

重要

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

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

Add(Choices, GrammarBuilder)

來源:
GrammarBuilder.cs
來源:
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.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 包含 SemanticResultValueSemanticResultKey 實例的 和 GrammarBuilder 物件與其他文法元素時,請務必避免使用相同的索引鍵名稱或多個語意元素來建立重複修改 Value 對象的 屬性的SemanticValue重複語意專案。 如果遇到這些情況,語音辨識器可能會擲回例外狀況。

另請參閱

適用於

Add(GrammarBuilder, GrammarBuilder)

來源:
GrammarBuilder.cs
來源:
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 支援下列類別的隱含轉換:

這個方法會接受上面 builder1 針對 或 builder2 參數列出的物件。

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

重要

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

另請參閱

適用於

Add(GrammarBuilder, String)

來源:
GrammarBuilder.cs
來源:
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.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 運算符。

另請參閱

適用於