Megosztás a következőn keresztül:


SpeechRecognizer.EmulateRecognize Method

Definition

Emulates input to the shared speech recognizer, using text instead of audio for synchronous speech recognition.

Overloads

EmulateRecognize(String)

Emulates input of a phrase to the shared speech recognizer, using text instead of audio for synchronous speech recognition.

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

Emulates input of specific words to the shared speech recognizer, using text instead of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

EmulateRecognize(String, CompareOptions)

Emulates input of a phrase to the shared speech recognizer, using text instead of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

Remarks

These methods bypass the system audio input. This can be helpful when you are testing or debugging an application or grammar.

Note

If Windows Speech Recognition is in the Sleeping state, then these methods return null.

The shared recognizer raises the SpeechDetected, SpeechHypothesized, SpeechRecognitionRejected, and SpeechRecognized events as if the recognition operation is not emulated. The recognizer ignores new lines and extra white space and treats punctuation as literal input.

Note

The RecognitionResult object generated by the shared recognizer in response to emulated input has a value of null for its Audio property.

To emulate asynchronous recognition, use the EmulateRecognizeAsync method.

EmulateRecognize(String)

Source:
SpeechRecognizer.cs
Source:
SpeechRecognizer.cs

Emulates input of a phrase to the shared speech recognizer, using text instead of audio for synchronous speech recognition.

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(System::String ^ inputText);
public System.Speech.Recognition.RecognitionResult EmulateRecognize (string inputText);
member this.EmulateRecognize : string -> System.Speech.Recognition.RecognitionResult
Public Function EmulateRecognize (inputText As String) As RecognitionResult

Parameters

inputText
String

The input for the recognition operation.

Returns

The recognition result for the recognition operation, or null, if the operation is not successful or Windows Speech Recognition is in the Sleeping state.

Examples

The following example loads a sample grammar to the shared recognizer and emulates input to the recognizer. If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition. If Windows Speech Recognition is in the Sleeping state, then EmulateRecognize always returns null.

using System;  
using System.Speech.Recognition;  

namespace SharedRecognizer  
{  
  class Program  
  {  

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

        RecognitionResult result;  

        // This EmulateRecognize call matches the grammar and returns a  
        // recognition result.  
        result = recognizer.EmulateRecognize("testing testing");  
        OutputResult(result);  

        // This EmulateRecognize call does not match the grammar and   
        // returns null.  
        result = recognizer.EmulateRecognize("testing one two three");  
        OutputResult(result);  
      }  

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Output information about a recognition result to the console.  
    private static void OutputResult(RecognitionResult result)  
    {  
      if (result != null)  
      {  
        Console.WriteLine("Recognition result = {0}",  
          result.Text ?? "<no text>");  
      }  
      else  
      {  
        Console.WriteLine("No recognition result");  
      }  
    }  
  }  
}  

Remarks

The recognizers that ship with Vista and Windows 7 ignore case and character width when applying grammar rules to the input phrase. For 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.

See also

Applies to

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

Source:
SpeechRecognizer.cs
Source:
SpeechRecognizer.cs

Emulates input of specific words to the shared speech recognizer, using text instead of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(cli::array <System::Speech::Recognition::RecognizedWordUnit ^> ^ wordUnits, System::Globalization::CompareOptions compareOptions);
public System.Speech.Recognition.RecognitionResult EmulateRecognize (System.Speech.Recognition.RecognizedWordUnit[] wordUnits, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognize : System.Speech.Recognition.RecognizedWordUnit[] * System.Globalization.CompareOptions -> System.Speech.Recognition.RecognitionResult
Public Function EmulateRecognize (wordUnits As RecognizedWordUnit(), compareOptions As CompareOptions) As RecognitionResult

Parameters

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.

Returns

The recognition result for the recognition operation, or null, if the operation is not successful or Windows Speech Recognition is in the Sleeping state.

Remarks

This method creates a RecognitionResult object using the information provided in the wordUnits parameter.

The recognizer uses the compareOptions when it applies grammar rules to the input phrase. 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. For more information about character width and Kana type, see the CompareOptions enumeration.

See also

Applies to

EmulateRecognize(String, CompareOptions)

Source:
SpeechRecognizer.cs
Source:
SpeechRecognizer.cs

Emulates input of a phrase to the shared speech recognizer, using text instead of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(System::String ^ inputText, System::Globalization::CompareOptions compareOptions);
public System.Speech.Recognition.RecognitionResult EmulateRecognize (string inputText, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognize : string * System.Globalization.CompareOptions -> System.Speech.Recognition.RecognitionResult
Public Function EmulateRecognize (inputText As String, compareOptions As CompareOptions) As RecognitionResult

Parameters

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.

Returns

The recognition result for the recognition operation, or null, if the operation is not successful or Windows Speech Recognition is in the Sleeping state.

Remarks

The recognizer uses the compareOptions when it applies grammar rules to the input phrase. 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. For more information about character width and Kana type, see the CompareOptions enumeration.

See also

Applies to