SemanticResultKey Constructor (String, String[])


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

public SemanticResultKey(
	string semanticResultKey,
	params string[] phrases


Type: System.String

The tag to be used access the SemanticValue instance associated with the Stringobjects specified by the phrases argument.

Type: System.String[]

One or more String objects, whose concatenated text will be associated with a SemanticValue object accessible with the tag defined in semanticResultKey.

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

SemanticResultKey stringTest=new SemanticResultKey("stringTest", 
                                new string[] {

The semanticResultKey argument determines the key used to access the SemanticValue which might be returned.

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".

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";

.NET Framework
Available since 3.0
Return to top