DictationGrammar 类

定义

表示用于自由文本口述的语音识别语法。Represents a speech recognition grammar used for free text dictation.

public ref class DictationGrammar : System::Speech::Recognition::Grammar
public class DictationGrammar : System.Speech.Recognition.Grammar
type DictationGrammar = class
    inherit Grammar
Public Class DictationGrammar
Inherits Grammar
继承
DictationGrammar

示例

下面的示例创建三个听写语法,将它们添加到新的 SpeechRecognitionEngine 对象中,并返回新的对象。The following example creates three dictation grammars, adds them to a new SpeechRecognitionEngine object, and returns the new object. 第一个语法是默认的听写语法。The first grammar is the default dictation grammar. 第二个语法是拼写听写语法。The second grammar is the spelling dictation grammar. 第三个语法是包含上下文短语的默认听写语法。The third grammar is the default dictation grammar that includes a context phrase. SetDictationContext方法用于在将上下文短语加载到对象后,将其与听写语法相关联 SpeechRecognitionEngineThe SetDictationContext method is used to associate the context phrase with the dictation grammar after it is loaded to the SpeechRecognitionEngine object.

private SpeechRecognitionEngine LoadDictationGrammars()  
{  

  // Create a default dictation grammar.  
  DictationGrammar defaultDictationGrammar = new DictationGrammar();  
  defaultDictationGrammar.Name = "default dictation";  
  defaultDictationGrammar.Enabled = true;  

  // Create the spelling dictation grammar.  
  DictationGrammar spellingDictationGrammar =  
    new DictationGrammar("grammar:dictation#spelling");  
  spellingDictationGrammar.Name = "spelling dictation";  
  spellingDictationGrammar.Enabled = true;  

  // Create the question dictation grammar.  
  DictationGrammar customDictationGrammar =  
    new DictationGrammar("grammar:dictation");  
  customDictationGrammar.Name = "question dictation";  
  customDictationGrammar.Enabled = true;  

  // Create a SpeechRecognitionEngine object and add the grammars to it.  
  SpeechRecognitionEngine recoEngine = new SpeechRecognitionEngine();  
  recoEngine.LoadGrammar(defaultDictationGrammar);  
  recoEngine.LoadGrammar(spellingDictationGrammar);  
  recoEngine.LoadGrammar(customDictationGrammar);  

  // Add a context to customDictationGrammar.  
  customDictationGrammar.SetDictationContext("How do you", null);  

  return recoEngine;  
}  

注解

此类为应用程序提供了一个预定义的语言模型,该模型可以处理文本中的用户输入。This class provides applications with a predefined language model that can process spoken user input into text. 此类支持默认对象和自定义 DictationGrammar 对象。This class supports both default and custom DictationGrammar objects. 有关选择听写语法的信息,请参阅 DictationGrammar(String) 构造函数。For information about selecting a dictation grammar, see the DictationGrammar(String) constructor.

默认情况下, DictationGrammar 语言模型为上下文可用。By default, the DictationGrammar language model is context free. 它不会使用特定的单词或字顺序来识别和解释音频输入。It does not make use of specific words or word order to identify and interpret audio input. 若要将上下文添加到听写语法,请使用 SetDictationContext 方法。To add context to the dictation grammar, use the SetDictationContext method.

备注

DictationGrammar 对象不支持 Priority 属性。DictationGrammar objects do not support the Priority property. DictationGrammarNotSupportedException如果 Priority 设置了,则引发。DictationGrammar throws a NotSupportedException if Priority is set.

构造函数

DictationGrammar()

初始化 DictationGrammar 类的新实例用于 Windows 桌面语音技术提供的默认命令语法。Initializes a new instance of the DictationGrammar class for the default dictation grammar provided by Windows Desktop Speech Technology.

DictationGrammar(String)

用特定的口述语法初始化 DictationGrammar 类的新实例。Initializes a new instance of the DictationGrammar class with a specific dictation grammar.

属性

Enabled

获取或设置一个值,此值控制语音识别器是否可以使用 Grammar 来进行识别。Gets or sets a value that controls whether a Grammar can be used by a speech recognizer to perform recognition.

(继承自 Grammar)
IsStg

获取语法是否是强类型的。Gets whether a grammar is strongly typed.

(继承自 Grammar)
Loaded

获取 Grammar 是否已经由语音识别器加载。Gets whether a Grammar has been loaded by a speech recognizer.

(继承自 Grammar)
Name

获取或设置 Grammar 对象的名称。Gets or sets the name of a Grammar object.

(继承自 Grammar)
Priority

获取或设置 Grammar 对象的优先级别值。Gets or sets the priority value of a Grammar object.

(继承自 Grammar)
ResourceName

使用用于加载当前 Grammar 的二进制资源名称获取或设置值。Gets or sets a value with the name of a binary resource that was used to load the current Grammar.

(继承自 Grammar)
RuleName

获取根规则或 Grammar 对象入口点的名称。Gets the name of the root rule or entry point of a Grammar object.

(继承自 Grammar)
Weight

获取或设置 Grammar 对象的宽度值。Gets or sets the weight value of a Grammar object.

(继承自 Grammar)

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetDictationContext(String, String)

添加上下文到由 SpeechRecognizerSpeechRecognitionEngine 对象加载的听写语法。Adds a context to a dictation grammar that has been loaded by a SpeechRecognizer or a SpeechRecognitionEngine object.

StgInit(Object[])

StgInit 方法初始的强类型语法。The StgInit method initializes a strongly-typed grammar.

(继承自 Grammar)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

事件

SpeechRecognized

当语音识别器执行使用 Grammar 对象的标识时引发。Raised when a speech recognizer performs recognition using the Grammar object.

(继承自 Grammar)

适用于

另请参阅