Implicit Conversion (String to GrammarBuilder)

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Implicitly converts a String object to an instance of GrammarBuilder.

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

Syntax

Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
	phrase As String _
) As GrammarBuilder
Visual Basic (Usage)
Dim input As String
Dim output As GrammarBuilder

output = CType(input, GrammarBuilder)
C#
public static implicit operator GrammarBuilder (
	string phrase
)

Parameters

phrase
Type: System..::..String

Valid instance of String to be implicitly converted to a containing GrammarBuilder object.

Return Value

Type: Microsoft.Speech.Recognition..::..GrammarBuilder

Returns an instance of SemanticResultValue containing the logical choice defined by the phrase argument.

Examples

The following example uses GrammarBuilder and Choices objects to construct a grammar that can recognize either of the two phrases, "Make background colorChoice" or "Set background to colorChoice".

After creating a list of acceptable values for colorChoice using a Choices object, the example initializes two GrammarBuilder objects, makePhrase and setPhrase, using implicit conversion from string objects.

The example finally creates a Grammar object from a Choices object cast to a GrammarBuilder object.

C# Copy imageCopy Code
private Grammar CreateColorGrammar()
{

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

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase = new GrammarBuilder("Make background");
  makePhrase.Append(colorElement);
  GrammarBuilder setPhrase = new GrammarBuilder("Set background to");
  setPhrase.Append(colorElement);

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

See Also