SrgsNameValueTag Constructors

Definition

Initializes a new instance of the SrgsNameValueTag class.

Overloads

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.

SrgsNameValueTag()

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

Initializes a new instance of the SrgsNameValueTag class.

public:
 SrgsNameValueTag();
public SrgsNameValueTag ();
Public Sub New ()

Applies to

SrgsNameValueTag(Object)

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

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

public:
 SrgsNameValueTag(System::Object ^ value);
public SrgsNameValueTag (object value);
new System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag : obj -> System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag
Public Sub New (value As Object)

Parameters

value
Object

The value used to set the Value property.

Exceptions

value is null.

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

Applies to

SrgsNameValueTag(String, Object)

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

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

public:
 SrgsNameValueTag(System::String ^ name, System::Object ^ value);
public SrgsNameValueTag (string name, object value);
new System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag : string * obj -> System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag
Public Sub New (name As String, value As Object)

Parameters

name
String

The string used to set the Name property on the SrgsNameValueTag object.

value
Object

The object used to set the Value property on the SrgsNameValueTag object.

Exceptions

value is null.

name is null.

name is an empty string.

Applies to