SrgsNameValueTag Class


Represents an element for associating a semantic value with a phrase in a grammar.

public ref class SrgsNameValueTag : System::Speech::Recognition::SrgsGrammar::SrgsElement
public class SrgsNameValueTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
type SrgsNameValueTag = class
    inherit SrgsElement
Public Class SrgsNameValueTag
Inherits SrgsElement


The following example creates a grammar for choosing the cities for a flight. The example uses SrgsNameValueTag to assign a semantic value to each city, which is the code for the city's airport.

The example constructs two SrgsRuleRef instances, each of which specifies a semantic key. Both rule references target the same SrgsRule object, named cities, but tag the recognition result from the rule reference with a different semantic key. The semantic key identifies a recognized city as the departure city or the arrival city for the flight. The handler for the SpeechRecognized event uses the keys to retrieve the semantics values created using SrgsNameValueTag from the recognition result.

using System;  
using System.Speech.Recognition;  
using System.Speech.Recognition.SrgsGrammar;  
namespace SampleRecognition  
  class Program  
    static void Main(string[] args)  
    // Initialize a SpeechRecognitionEngine object.  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
        // Build a rule with a list of cities, assign a semantic value to each city.  
        SrgsItem chi = new SrgsItem("Chicago");  
        chi.Add(new SrgsNameValueTag("ORD"));  
        SrgsItem bos = new SrgsItem("Boston");  
        bos.Add(new SrgsNameValueTag("BOS"));  
        SrgsItem mia = new SrgsItem("Miami");  
        mia.Add(new SrgsNameValueTag("MIA"));  
        SrgsItem dal = new SrgsItem("Dallas");  
        dal.Add(new SrgsNameValueTag("DFW"));  
        SrgsOneOf cities = new SrgsOneOf(new SrgsItem[] { chi, bos, mia, dal });  
        SrgsRule citiesRule = new SrgsRule("flightCities");  
        // Build the root rule, add rule references to the cities rule.  
        SrgsRule flightBooker = new SrgsRule("bookFlight");  
        flightBooker.Add(new SrgsItem("I want to fly from"));  
        flightBooker.Add(new SrgsRuleRef(citiesRule, "departureCity"));  
        flightBooker.Add(new SrgsItem("to"));  
        flightBooker.Add(new SrgsRuleRef(citiesRule, "arrivalCity"));  
        // Build an SrgsDocument object from the flightBooker rule and add the cities rule.  
        SrgsDocument cityChooser = new SrgsDocument(flightBooker);  
        // Create a Grammar object from the SrgsDocument and load it to the recognizer.  
        Grammar departArrive = new Grammar(cityChooser);  
        departArrive.Name = ("Cities Grammar");  
        // Configure recognizer input.  
        // Attach a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        // Start asynchronous recognition.  
        Console.WriteLine("Starting asynchronous recognition...");  
        // Keep the console window open.  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
      Console.WriteLine("Semantic results:");  
      Console.WriteLine("  The departure city is: " + e.Result.Semantics["departureCity"].Value);  
      Console.WriteLine("  The destination city is: " + e.Result.Semantics["arrivalCity"].Value);  


This object is similar to the tag element defined by the World Wide Web Consortium (W3C) Speech Recognition Grammar Specification (SRGS) Version 1.0.. However, the Value property of this object cannot be script. The contents of Value can be of the type Boolean, Double, Int32, or String. String values must be enclosed in double quotes.

To add semantics as script, use SrgsSemanticInterpretationTag.



Initializes a new instance of the SrgsNameValueTag class.


Initializes a new instance of the SrgsNameValueTag class, specifying a value for the instance.

SrgsNameValueTag(String, Object)

Initializes a new instance of the SrgsNameValueTag class, specifying a name and a value for the instance.



Gets or sets the name of the SrgsNameValueTag instance.


Gets or sets the value contained in the SrgsNameValueTag instance.



Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)

Determines whether the specified object is equal to the current object.

(Inherited from Object)

Serves as the default hash function.

(Inherited from Object)

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)

Gets the Type of the current instance.

(Inherited from Object)

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)

Creates a shallow copy of the current Object.

(Inherited from Object)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also