GrammarBuilder Implicit Conversion (SemanticResultKey to GrammarBuilder)

 
equivalentCodeEntityM:System.Speech.Recognition.GrammarBuilder.#ctor(System.Speech.Recognition.SemanticResultKey)

Converts a SemanticResultKey object to a GrammarBuilder object.

Namespace:   System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public static implicit operator GrammarBuilder (
	SemanticResultKey semanticKey
)

Parameters

semanticKey
Type: System.Speech.Recognition.SemanticResultKey

The semantic key to convert.

Return Value

Type: System.Speech.Recognition.GrammarBuilder

The converted SemanticResultKey object.

Implicit conversion creates a new instance of GrammarBuilder. This conversion operator is equivalent to calling GrammarBuilder and specifying semanticKey for the key.

The following example creates a speech recognition grammar that can recognize a response to a "yes" or "no" question. The implicit conversion operator is used in the construction of a SemanticResultValue object from a Choices object, in the construction of a Choices object from two SemanticResultValue objects, and in the construction of a Grammar object from a SemanticResultKey object.

Choices yesChoices = new Choices(new string[] {"yes", "yup", "yah"});
SemanticResultValue yesValue =
  new SemanticResultValue(yesChoices, true);

Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });
SemanticResultValue noValue =
  new SemanticResultValue(noChoices, false);

SemanticResultKey yesnoKey =
  new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));

Grammar yesnoGrammar = new Grammar(yesnoKey);
yesnoGrammar.Name = "yesno";

.NET Framework
Available since 3.0
Return to top
Show: