SrgsNameValueTag Class

 

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

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

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

[SerializableAttribute]
public ref class SrgsNameValueTag : SrgsElement

NameDescription
System_CAPS_pubmethodSrgsNameValueTag()

Initializes a new instance of the SrgsNameValueTag class.

System_CAPS_pubmethodSrgsNameValueTag(Object^)

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

System_CAPS_pubmethodSrgsNameValueTag(String^, Object^)

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

NameDescription
System_CAPS_pubpropertyName

Gets or sets the name of the SrgsNameValueTag instance.

System_CAPS_pubpropertyValue

Gets or sets the value contained in the SrgsNameValueTag instance.

NameDescription
System_CAPS_pubmethodCreateObjRef(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.)

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

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 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);
    }
  }
}

.NET Framework
Available since 3.0

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

Return to top
Show: