GrammarBuilder.Add Método
Definição
Cria um novo GrammarBuilder que contém uma sequência de dois elementos de gramática.Creates a new GrammarBuilder that contains a sequence of two grammar elements.
Sobrecargas
| Add(Choices, GrammarBuilder) |
Cria um novo GrammarBuilder que contém um objeto Choices seguido por um objeto GrammarBuilder.Creates a new GrammarBuilder that contains a Choices object followed by a GrammarBuilder object. |
| Add(GrammarBuilder, Choices) |
Cria um novo GrammarBuilder que contém um objeto GrammarBuilder seguido por um objeto Choices.Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a Choices object. |
| Add(GrammarBuilder, GrammarBuilder) |
Cria um novo GrammarBuilder que contém uma sequência de dois objetos GrammarBuilder.Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects. |
| Add(GrammarBuilder, String) |
Cria um novo GrammarBuilder que contém um objeto GrammarBuilder seguido por uma frase.Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a phrase. |
| Add(String, GrammarBuilder) |
Cria um novo GrammarBuilder que contém uma frase seguida por um objeto GrammarBuilder.Creates a new GrammarBuilder that contains a phrase followed by a GrammarBuilder object. |
Comentários
Os métodos estáticos Add fornecem outro mecanismo pelo qual você pode combinar vários tipos para criar diversidade e flexibilidade em gramáticas criadas com o GrammarBuilder .The static Add methods provide another mechanism by which you can combine various types to create diversity and flexibility in grammars built with GrammarBuilder. Esses métodos correspondem aos métodos estáticos Addition , que também são definidos na GrammarBuilder classe.These methods correspond to the static Addition methods, which are also defined on the GrammarBuilder class. A ordem dos parâmetros determina a ordem dos elementos no novo GrammarBuilder .The order of the parameters determines the order of the elements in the new GrammarBuilder.
Um GrammarBuilder também pode ser obtido de Choices SemanticResultKey objetos de cadeia de caracteres,, SemanticResultValue e. A GrammarBuilder can also be obtained from Choices, SemanticResultKey, SemanticResultValue, and String objects. Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.
Importante
O reconhecedor de fala pode gerar uma exceção ao usar uma gramática de reconhecimento de fala que contém elementos semânticos duplicados com o mesmo nome de chave ou vários elementos semânticos que poderiam modificar repetidamente o valor do mesmo elemento semântico.The speech recognizer can throw an exception when using a speech recognition grammar that contains duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the value of the same semantic element.
Para obter mais informações sobre como criar e usar gramáticas de reconhecimento de fala, consulte reconhecimento de fala.For more information about building and using speech recognition grammars, see Speech Recognition.
Add(Choices, GrammarBuilder)
Cria um novo GrammarBuilder que contém um objeto Choices seguido por um objeto GrammarBuilder.Creates a new GrammarBuilder that contains a Choices object followed by a GrammarBuilder object.
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
Parâmetros
- choices
- Choices
O primeiro elemento de gramática, que representa um conjunto de alternativas.The first grammar element, which represents a set of alternatives.
- builder
- GrammarBuilder
O segundo elemento de gramática.The second grammar element.
Retornos
Um GrammarBuilder para a sequência do elemento choices seguido pelo elemento builder.A GrammarBuilder for the sequence of the choices element followed by the builder element.
Comentários
GrammarBuilder dá suporte a conversões implícitas das seguintes classes:GrammarBuilder supports implicit conversions from the following classes:
Esse método aceita os objetos listados acima para o builder parâmetro.This method accepts the objects listed above for the builder parameter.
Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.
Importante
Ao combinar Choices e GrammarBuilder objetos que contêm SemanticResultValue ou SemanticResultKey instâncias, Evite criar elementos semânticos duplicados com o mesmo nome de chave ou vários elementos semânticos que poderiam modificar repetidamente a Value propriedade de um SemanticValue objeto.When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. O reconhecedor de fala pode gerar uma exceção se encontrar essas circunstâncias.The speech recognizer can throw an exception if it encounters these circumstances. Para obter mais informações sobre como criar uma gramática de reconhecimento de fala que contenha informações semânticas, consulte Adicionar semântica a uma gramática GrammarBuilder.For more information about building a speech recognition grammar that contains semantic information, see Add Semantics to a GrammarBuilder Grammar.
Confira também
Aplica-se a
Add(GrammarBuilder, Choices)
Cria um novo GrammarBuilder que contém um objeto GrammarBuilder seguido por um objeto Choices.Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a Choices object.
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
Parâmetros
- builder
- GrammarBuilder
O primeiro elemento de gramática.The first grammar element.
- choices
- Choices
O segundo elemento de gramática, que representa um conjunto de alternativas.The second grammar element, which represents a set of alternatives.
Retornos
Um GrammarBuilder para a sequência do elemento builder seguido pelo elemento choices.A GrammarBuilder for the sequence of the builder element followed by the choices element.
Exemplos
O exemplo a seguir cria uma gramática de reconhecimento de fala que pode reconhecer as duas frases, "Make background Color" e "Set Background to Color", em que Color é selecionado de um conjunto de cores.The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Vários tipos são usados para criar a gramática final, como objetos String, Choices e GrammarBuilder .Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. Os operadores de conversão explícita nas chamadas para os Add métodos são opcionais.The explicit cast operators in the calls to the Add methods are optional.
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;
}
Comentários
GrammarBuilder dá suporte a conversões implícitas das seguintes classes:GrammarBuilder supports implicit conversions from the following classes:
Esse método aceita os objetos listados acima para o builder parâmetro.This method accepts the objects listed above for the builder parameter.
Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.
Importante
Ao combinar Choices e GrammarBuilder objetos que contêm SemanticResultValue ou SemanticResultKey instâncias com outros elementos de gramática, Evite criar elementos semânticos duplicados com o mesmo nome de chave ou vários elementos semânticos que poderiam modificar repetidamente a Value propriedade de um SemanticValue objeto.When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances with other grammar elements, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. O reconhecedor de fala pode gerar uma exceção se encontrar essas circunstâncias.The speech recognizer can throw an exception if it encounters these circumstances.
Confira também
Aplica-se a
Add(GrammarBuilder, GrammarBuilder)
Cria um novo GrammarBuilder que contém uma sequência de dois objetos GrammarBuilder.Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects.
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
Parâmetros
- builder1
- GrammarBuilder
O primeiro elemento de gramática.The first grammar element.
- builder2
- GrammarBuilder
O segundo elemento de gramática.The second grammar element.
Retornos
Um GrammarBuilder para a sequência do elemento builder1 seguido pelo elemento builder2.A GrammarBuilder for the sequence of the builder1 element followed by the builder2 element.
Exemplos
O exemplo a seguir cria uma gramática de reconhecimento de fala que pode reconhecer as duas frases, "Make background Color" e "Set Background to Color", em que Color é selecionado de um conjunto de cores.The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Vários tipos são usados para criar a gramática final, como objetos String, Choices e GrammarBuilder .Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. Os operadores de conversão explícita nas chamadas para os Add métodos são opcionais.The explicit cast operators in the calls to the Add methods are optional.
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;
}
Comentários
GrammarBuilder dá suporte a conversões implícitas das seguintes classes:GrammarBuilder supports implicit conversions from the following classes:
Esse método aceita os objetos listados acima para o builder1 builder2 parâmetro ou.This method accepts the objects listed above for the builder1 or builder2 parameter.
Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.
Importante
Ao combinar Choices e GrammarBuilder objetos que contêm SemanticResultValue ou SemanticResultKey instâncias com outros elementos de gramática, Evite criar elementos semânticos duplicados com o mesmo nome de chave ou vários elementos semânticos que poderiam modificar repetidamente a Value propriedade de um SemanticValue objeto.When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances with other grammar elements, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. O reconhecedor de fala pode gerar uma exceção se encontrar essas circunstâncias.The speech recognizer can throw an exception if it encounters these circumstances.
Confira também
Aplica-se a
Add(GrammarBuilder, String)
Cria um novo GrammarBuilder que contém um objeto GrammarBuilder seguido por uma frase.Creates a new GrammarBuilder that contains a GrammarBuilder object followed by a phrase.
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
Parâmetros
- builder
- GrammarBuilder
O primeiro elemento de gramática.The first grammar element.
- phrase
- String
O segundo elemento de gramática, que representa uma sequência de palavras.The second grammar element, which represents a sequence of words.
Retornos
Um GrammarBuilder para a sequência do elemento builder seguido pelo elemento phrase.A GrammarBuilder for the sequence of the builder element followed by the phrase element.
Exemplos
O exemplo a seguir cria uma gramática de reconhecimento de fala que pode reconhecer as duas frases, "Make background Color" e "Set Background to Color", em que Color é selecionado de um conjunto de cores.The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Vários tipos são usados para criar a gramática final, como objetos String, Choices e GrammarBuilder .Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. Os operadores de conversão explícita nas chamadas para os Add métodos são opcionais.The explicit cast operators in the calls to the Add methods are optional.
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;
}
Comentários
GrammarBuilder dá suporte a conversões implícitas das seguintes classes:GrammarBuilder supports implicit conversions from the following classes:
Esse método aceita os objetos listados acima para o builder parâmetro.This method accepts the objects listed above for the builder parameter.
Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.
Confira também
Aplica-se a
Add(String, GrammarBuilder)
Cria um novo GrammarBuilder que contém uma frase seguida por um objeto GrammarBuilder.Creates a new GrammarBuilder that contains a phrase followed by a GrammarBuilder object.
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
Parâmetros
- phrase
- String
O primeiro elemento de gramática, que representa uma sequência de palavras.The first grammar element, which represents a sequence of words.
- builder
- GrammarBuilder
O segundo elemento de gramática.The second grammar element.
Retornos
Um GrammarBuilder para a sequência do elemento phrase seguido pelo elemento builder.A GrammarBuilder for the sequence of the phrase element followed by the builder element.
Exemplos
O exemplo a seguir cria uma gramática de reconhecimento de fala que pode reconhecer as duas frases, "Make background Color" e "Set Background to Color", em que Color é selecionado de um conjunto de cores.The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Vários tipos são usados para criar a gramática final, como objetos String, Choices e GrammarBuilder .Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects. Os operadores de conversão explícita nas chamadas para os Add métodos são opcionais.The explicit cast operators in the calls to the Add methods are optional.
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;
}
Comentários
GrammarBuilder dá suporte a conversões implícitas das seguintes classes:GrammarBuilder supports implicit conversions from the following classes:
Esse método aceita os objetos listados acima para o builder parâmetro.This method accepts the objects listed above for the builder parameter.
Para obter mais informações, consulte Implicit os Addition operadores e.For more information, see the Implicit and Addition operators.