Delen via


Note

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

SemanticResultKey Constructor (String, String[])

Assigns a semantic key to one or more String instances used to create a speech recognition grammar.

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

Syntax

'Declaration
Public Sub New ( _
    semanticResultKey As String, _
    ParamArray phrases As String() _
)
'Usage
Dim semanticResultKey As String
Dim phrases As String()

Dim instance As New SemanticResultKey(semanticResultKey, _
    phrases)
public SemanticResultKey(
    string semanticResultKey,
    params string[] phrases
)

Parameters

  • semanticResultKey
    Type: System.String
    The tag to be used to access the SemanticValue instance associated with the Stringobjects specified by the phrases argument.
  • phrases
    Type: []
    One or more String objects whose concatenated text will be associated with a SemanticValue object accessible with the tag defined in semanticResultKey.

Remarks

When performing a recognition operation, the String instances referred to in the phrases argument are treated as sequential. For example, if the following SemanticResultValue is used to construct a Grammar, input to the recognition engine must contain "the quick brown fox" to be recognized.

SemanticResultKey stringTest=new SemanticResultKey("stringTest", 
                                new string[] {
                                               "the",
                                               "quick",
                                               "brown",
                                               "fox"});

The semanticResultKey argument determines the key used to access the SemanticValue.

If you construct a Grammar using a GrammarBuilder object that contains a semantic key with an array of string objects, the Value of the SemanticValue produced by a recognition operation will be the string used in recognition. In the preceding example, this means that Value would be "the quick brown fox".

Examples

The following example creates a Grammar from a GrammarBuilder object that uses a SemanticResultKey, which is defined by an array of String objects.

A recognition engine using the Grammar created will recognize the phrase "color red green blue zero". The semantics of the RecognizedPhrase returned by recognition will contain a SemanticValue with a Value of "red green blue". You can access the SemanticValue using the "code" tag.

Because of the SemanticResultValue("zero", 5) appended to the GrammarBuilder, the root SemanticValue object in the RecognizedPhrase will have a value of 5.

private void keyTest()
  { 
  //Say "color red green blue zero"
  GrammarBuilder gb = new GrammarBuilder("color") +
                        new SemanticResultKey("code", 
                          (new string[] {"red", "green", "blue"})) +
                        new SemanticResultValue("zero", 5);
  Grammar g = new Grammar(gb);
  g.Name = "keyTest";
  _recognizer.LoadGrammar(g);
}

See Also

Reference

SemanticResultKey Class

SemanticResultKey Members

SemanticResultKey Overload

Microsoft.Speech.Recognition Namespace