Partilhar via


SrgsNameValueTag Construtores

Definição

Inicializa uma nova instância da classe SrgsNameValueTag.

Sobrecargas

SrgsNameValueTag()

Inicializa uma nova instância da classe SrgsNameValueTag.

SrgsNameValueTag(Object)

Inicializa uma nova instância da classe SrgsNameValueTag, especificando um valor para a instância.

SrgsNameValueTag(String, Object)

Inicializa uma nova instância da classe SrgsNameValueTag, especificando um nome e um valor para a instância.

SrgsNameValueTag()

Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs

Inicializa uma nova instância da classe SrgsNameValueTag.

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

Aplica-se a

SrgsNameValueTag(Object)

Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs

Inicializa uma nova instância da classe SrgsNameValueTag, especificando um valor para a instância.

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)

Parâmetros

value
Object

O valor usado para definir a propriedade Value.

Exceções

value é null.

Exemplos

O exemplo a seguir cria uma gramática para escolher as cidades para um voo. O exemplo usa SrgsNameValueTag para atribuir um valor semântico a cada cidade, que é o código para o aeroporto da cidade.

O exemplo constrói duas SrgsRuleRef instâncias, cada uma especificando uma chave semântica. Ambas as referências de regra visam o mesmo SrgsRule objeto, chamado cities, mas marcam o resultado do reconhecimento da referência de regra com uma chave semântica diferente. A chave semântica identifica uma cidade reconhecida como a cidade de partida ou a cidade de chegada para o voo. O manipulador do SpeechRecognized evento usa as chaves para recuperar os valores de semântica criados usando SrgsNameValueTag o resultado do reconhecimento.

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

Aplica-se a

SrgsNameValueTag(String, Object)

Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs
Origem:
SrgsNameValueTag.cs

Inicializa uma nova instância da classe SrgsNameValueTag, especificando um nome e um valor para a instância.

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)

Parâmetros

name
String

A cadeia de caracteres usada para definir a propriedade Name no objeto SrgsNameValueTag.

value
Object

O objeto usado para definir a propriedade Value no objeto SrgsNameValueTag.

Exceções

value é null.

name é null.

name é uma cadeia de caracteres vazia.

Aplica-se a