SrgsNameValueTag 类

定义

表示关联一个语义值与语法短语的元素。

public ref class SrgsNameValueTag : System::Speech::Recognition::SrgsGrammar::SrgsElement
[System.Serializable]
public class SrgsNameValueTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
public class SrgsNameValueTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
[<System.Serializable>]
type SrgsNameValueTag = class
    inherit SrgsElement
type SrgsNameValueTag = class
    inherit SrgsElement
Public Class SrgsNameValueTag
Inherits SrgsElement
继承
属性

示例

以下示例创建一个语法,用于为航班选择城市。 该示例使用 SrgsNameValueTag 将语义值分配给每个城市,即城市机场的代码。

该示例构造两 SrgsRuleRef 个 实例,每个实例指定一个语义键。 这两个规则引用都针对同一 SrgsRule 对象,名为 cities,但使用不同的语义键标记规则引用的识别结果。 语义键将已识别的城市标识为航班的出发城市或到达城市。 事件的处理程序 SpeechRecognized 使用键从识别结果中检索使用 SrgsNameValueTag 创建的语义值。

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

注解

此对象类似于 tag 万维网联合会 (W3C) 语音识别语法规范 (SRGS) 版本 1.0.定义的元素。 但是, Value 此对象的 属性不能是脚本。 的内容Value可以是 、、 DoubleInt32String类型Boolean。 字符串值必须用双引号引起来。

若要将语义添加为脚本,请使用 SrgsSemanticInterpretationTag

构造函数

SrgsNameValueTag()

初始化 SrgsNameValueTag 类的新实例。

SrgsNameValueTag(Object)

在指定实例值的情况下,初始化 SrgsNameValueTag 类的新实例。

SrgsNameValueTag(String, Object)

初始化 SrgsNameValueTag 类的新实例,同时指定实例的名称和值。

属性

Name

获取或设置 SrgsNameValueTag 实例的名称。

Value

获取或设置 SrgsNameValueTag 中包含的值。

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅