Export (0) Print
Expand All

SpeechRecognizer.EmulateRecognize Method (String)

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

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public RecognitionResult EmulateRecognize(
	string inputText
)

Parameters

inputText
Type: System.String

The input for the recognition operation.

Return Value

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

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.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft