Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

GrammarBuilder Implicit Conversion (String to GrammarBuilder)

Implicitly converts a String object to an instance of GrammarBuilder.

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

Syntax

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

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

Parameters

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.

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

Reference

GrammarBuilder Class

GrammarBuilder Members

Implicit Overload

Microsoft.Speech.Recognition Namespace

GrammarBuilder