SrgsNameValueTag Class

Definition

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

public ref class SrgsNameValueTag : System::Speech::Recognition::SrgsGrammar::SrgsElement
[System.Serializable]
public class SrgsNameValueTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
type SrgsNameValueTag = class
    inherit SrgsElement
Public Class SrgsNameValueTag
Inherits SrgsElement
Inheritance
Attributes

Examples

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");  
        citiesRule.Add(cities);  
  
        // 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);  
        cityChooser.Rules.Add(citiesRule);  
  
        // Create a Grammar object from the SrgsDocument and load it to the recognizer.  
        Grammar departArrive = new Grammar(cityChooser);  
        departArrive.Name = ("Cities Grammar");  
        recognizer.LoadGrammarAsync(departArrive);  
  
        // Configure recognizer input.  
        recognizer.SetInputToDefaultAudioDevice();  
  
        // Attach a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
  
        // Start asynchronous recognition.  
        recognizer.RecognizeAsync();  
        Console.WriteLine("Starting asynchronous recognition...");  
  
        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  
  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
      Console.WriteLine();  
      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);  
    }  
  }  
}  

Remarks

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.

Constructors

SrgsNameValueTag()

Initializes a new instance of the SrgsNameValueTag class.

SrgsNameValueTag(Object)

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.

Properties

Name

Gets or sets the name of the SrgsNameValueTag instance.

Value

Gets or sets the value contained in the SrgsNameValueTag instance.

Methods

CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
Equals(Object)

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

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also