This documentation is archived and is not being maintained.

SrgsNameValueTag Class

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

System::Object
  System::MarshalByRefObject
    System.Speech.Recognition.SrgsGrammar::SrgsElement
      System.Speech.Recognition.SrgsGrammar::SrgsNameValueTag

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

[SerializableAttribute]
public ref class SrgsNameValueTag : public SrgsElement

The SrgsNameValueTag type exposes the following members.

  NameDescription
Public methodSrgsNameValueTag()Initializes a new instance of the SrgsNameValueTag class.
Public methodSrgsNameValueTag(Object)Initializes a new instance of the SrgsNameValueTag class, specifying a value for the instance.
Public methodSrgsNameValueTag(String, Object)Initializes a new instance of the SrgsNameValueTag class, specifying a name and a value for the instance.
Top

  NameDescription
Public propertyNameGets or sets the name of the SrgsNameValueTag instance.
Public propertyValueGets or sets the value contained in the SrgsNameValueTag instance.
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

The following example creates a grammar for choosing the cities for a flight. The example uses SrgsNameValueTag(Object) 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(Object) 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);
    }
  }
}

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: