SpeechRecognizer.EmulateRecognizeAsync 方法

定义

使用文本而不是异步语音识别的音频来模拟输入到共享语音识别器。Emulates input to the shared speech recognizer, using text instead of audio for asynchronous speech recognition.

重载

EmulateRecognizeAsync(String)

使用文本而不是异步语音识别的音频来模拟输入短语到共享语音识别器。Emulates input of a phrase to the shared speech recognizer, using text instead of audio for asynchronous speech recognition.

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

使用文本代替异步语音识别的音频来模拟特定字输入到共享语音识别器,并指定识别器如何处理单词和加载的语音识别语法间的 Unicode 比较。Emulates input of specific words to the shared speech recognizer, using text instead of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

EmulateRecognizeAsync(String, CompareOptions)

使用文本代替异步语音识别的音频来模拟短语输入到共享语音识别器,并指定识别器如何处理短语和加载的语音识别语法间的 Unicode 比较。Emulates input of a phrase to the shared speech recognizer, using text instead of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

注解

这些方法不使用系统音频输入。These methods bypass the system audio input. 这在测试或调试应用程序或语法时非常有用。This can be helpful when you are testing or debugging an application or grammar.

共享识别器会引发SpeechDetectedSpeechHypothesizedSpeechRecognitionRejectedSpeechRecognized事件,就好像未模拟识别操作一样。The shared recognizer raises the SpeechDetected, SpeechHypothesized, SpeechRecognitionRejected, and SpeechRecognized events as if the recognition operation is not emulated. 当识别器完成异步识别操作时,它会引发EmulateRecognizeCompleted事件。When the recognizer completes the asynchronous recognition operation, it raises the EmulateRecognizeCompleted event. 识别器忽略新行和额外的空格,并将标点符号视为文本输入。The recognizer ignores new lines and extra white space and treats punctuation as literal input.

备注

如果 Windows 语音识别处于睡眠状态,则共享识别器不处理输入,也不会引发SpeechDetected和相关事件, EmulateRecognizeCompleted但仍会引发事件。If Windows Speech Recognition is in the Sleeping state, then the shared recognizer does not process input and does not raise the SpeechDetected and related events, but still raises the EmulateRecognizeCompleted event.

备注

共享识别器为响应仿真输入而生成的null Audio对象的属性值为。 RecognitionResultThe RecognitionResult object generated by the shared recognizer in response to emulated input has a value of null for its Audio property.

若要模拟同步识别,请EmulateRecognize使用方法。To emulate synchronous recognition, use the EmulateRecognize method.

EmulateRecognizeAsync(String)

使用文本而不是异步语音识别的音频来模拟输入短语到共享语音识别器。Emulates input of a phrase to the shared speech recognizer, using text instead of audio for asynchronous speech recognition.

public:
 void EmulateRecognizeAsync(System::String ^ inputText);
public void EmulateRecognizeAsync (string inputText);
member this.EmulateRecognizeAsync : string -> unit
Public Sub EmulateRecognizeAsync (inputText As String)

参数

inputText
String

标识操作的输入。The input for the recognition operation.

示例

下面的示例是一个控制台应用程序的一部分,该应用程序加载语音识别语法并演示异步仿真输入、关联的识别结果和语音识别器引发的相关事件。The following example is part of a console application that loads a speech recognition grammar and demonstrates asynchronous emulated input, the associated recognition results, and the associated events raised by the speech recognizer. 如果 Windows 语音识别未运行,则启动此应用程序也将启动 Windows 语音识别。If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition. 如果 Windows 语音识别处于睡眠状态,则EmulateRecognizeAsync始终返回 null。If Windows Speech Recognition is in the Sleeping state, then EmulateRecognizeAsync always returns null.

using System;  
using System.Speech.Recognition;  
using System.Threading;  
  
namespace SharedRecognizer  
{  
  class Program  
  {  
    static bool completed;  
  
    static void Main(string[] args)  
    {  
      // Initialize an instance of the shared recognizer.  
      using (SpeechRecognizer recognizer = new SpeechRecognizer())  
      {  
        // Create and load a sample grammar.  
        Grammar testGrammar =  
          new Grammar(new GrammarBuilder("testing testing"));  
        testGrammar.Name = "Test Grammar";  
  
        recognizer.LoadGrammar(testGrammar);  
  
        // Attach event handlers for recognition events.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(  
            SpeechRecognizedHandler);  
        recognizer.EmulateRecognizeCompleted +=  
          new EventHandler<EmulateRecognizeCompletedEventArgs>(  
            EmulateRecognizeCompletedHandler);  
  
        completed = false;  
  
        // This EmulateRecognizeAsync call generates a SpeechRecognized event.  
        recognizer.EmulateRecognizeAsync("testing testing");  
  
        // Wait for the asynchronous operation to complete.  
        while (!completed)  
        {  
          Thread.Sleep(333);  
        }  
  
        completed = false;  
  
        // This EmulateRecognizeAsync call does not match the grammar   
        // or generate a SpeechRecognized event.  
        recognizer.EmulateRecognizeAsync("testing one two three");  
  
        // Wait for the asynchronous operation to complete.  
        while (!completed)  
        {  
          Thread.Sleep(333);  
        }  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  
    // Handle the SpeechRecognized event.  
    static void SpeechRecognizedHandler(  
      object sender, SpeechRecognizedEventArgs e)  
    {  
      if (e.Result != null)  
      {  
        Console.WriteLine("Recognition result = {0}",  
          e.Result.Text ?? "<no text>");  
      }  
      else  
      {  
        Console.WriteLine("No recognition result");  
      }  
    }  
  
    // Handle the EmulateRecognizeCompleted event.   
    static void EmulateRecognizeCompletedHandler(  
      object sender, EmulateRecognizeCompletedEventArgs e)  
    {  
      if (e.Result == null)  
      {  
        Console.WriteLine("No result generated.");  
      }  
  
      completed = true;  
    }  
  }  
}  
  

注解

向输入短语应用语法规则时,Vista 和 Windows 7 附带的识别器忽略大小写和字符宽度。The recognizers that ship with Vista and Windows 7 ignore case and character width when applying grammar rules to the input phrase. 有关此类比较的详细信息,请参阅CompareOptions枚举值OrdinalIgnoreCaseIgnoreWidthFor more information about this type of comparison, see the CompareOptions enumeration values OrdinalIgnoreCase and IgnoreWidth. 识别器还会忽略新行和额外的空格,并将标点符号视为文本输入。The recognizers also ignore new lines and extra white space and treat punctuation as literal input.

另请参阅

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

使用文本代替异步语音识别的音频来模拟特定字输入到共享语音识别器,并指定识别器如何处理单词和加载的语音识别语法间的 Unicode 比较。Emulates input of specific words to the shared speech recognizer, using text instead of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

public:
 void EmulateRecognizeAsync(cli::array <System::Speech::Recognition::RecognizedWordUnit ^> ^ wordUnits, System::Globalization::CompareOptions compareOptions);
public void EmulateRecognizeAsync (System.Speech.Recognition.RecognizedWordUnit[] wordUnits, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognizeAsync : System.Speech.Recognition.RecognizedWordUnit[] * System.Globalization.CompareOptions -> unit

参数

wordUnits
RecognizedWordUnit[]

词单元数组,包含识别操作输入。An array of word units that contains the input for the recognition operation.

compareOptions
CompareOptions

描述用于模拟识别操作的比较说明类型的枚举值的按位组合。A bitwise combination of the enumeration values that describe the type of comparison to use for the emulated recognition operation.

注解

此方法使用wordUnits参数RecognitionResult中提供的信息创建对象。This method creates a RecognitionResult object using the information provided in the wordUnits parameter.

compareOptions当识别器将语法规则应用于输入短语时,将使用。The recognizer uses the compareOptions when it applies grammar rules to the input phrase. 如果OrdinalIgnoreCaseIgnoreCase值存在,则 Vista 和 Windows 7 附带的识别器会忽略大小写。The recognizers that ship with Vista and Windows 7 ignore case if the OrdinalIgnoreCase or IgnoreCase value is present. 识别器始终忽略字符宽度并从不忽略假名类型。The recognizers always ignore the character width and never ignore the Kana type. 识别器还会忽略新行和额外的空格,并将标点符号视为文本输入。The recognizers also ignore new lines and extra white space and treats punctuation as literal input. 有关字符宽度和假名类型的详细信息,请参阅CompareOptions枚举。For more information about character width and Kana type, see the CompareOptions enumeration.

另请参阅

EmulateRecognizeAsync(String, CompareOptions)

使用文本代替异步语音识别的音频来模拟短语输入到共享语音识别器,并指定识别器如何处理短语和加载的语音识别语法间的 Unicode 比较。Emulates input of a phrase to the shared speech recognizer, using text instead of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

public:
 void EmulateRecognizeAsync(System::String ^ inputText, System::Globalization::CompareOptions compareOptions);
public void EmulateRecognizeAsync (string inputText, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognizeAsync : string * System.Globalization.CompareOptions -> unit

参数

inputText
String

标识操作的输入相。The input phrase for the recognition operation.

compareOptions
CompareOptions

描述用于模拟识别操作的比较说明类型的枚举值的按位组合。A bitwise combination of the enumeration values that describe the type of comparison to use for the emulated recognition operation.

注解

compareOptions当识别器将语法规则应用于输入短语时,将使用。The recognizer uses the compareOptions when it applies grammar rules to the input phrase. 如果OrdinalIgnoreCaseIgnoreCase值存在,则 Vista 和 Windows 7 附带的识别器会忽略大小写。The recognizers that ship with Vista and Windows 7 ignore case if the OrdinalIgnoreCase or IgnoreCase value is present. 识别器始终忽略字符宽度并从不忽略假名类型。The recognizers always ignore the character width and never ignore the Kana type. 识别器还会忽略新行和额外的空格,并将标点符号视为文本输入。The recognizers also ignore new lines and extra white space and treats punctuation as literal input. 有关字符宽度和假名类型的详细信息,请参阅CompareOptions枚举。For more information about character width and Kana type, see the CompareOptions enumeration.

另请参阅

适用于