Share via


Emulate Spoken Commands

Emulation of spoken commands is useful for debugging a speech recognition application during its development. Using emulated recognition, you can input a phrase as text to a speech recognition engine that has a grammar loaded, and determine whether or not the phrase is in the grammar. You can also examine the recognition result produced for the phrase.

The EmulateRecognize and EmulateRecognizeAsync overloaded methods on the SpeechRecognizer and SpeechRecognitionEngine classes can be used to programmatically emulate speech recognition using text as input.

Example

The following example creates a grammar and loads it into the speech recognizer. It then uses the EmulateRecognize(String) method to send the string "this is a test " to the speech recognizer.

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      sr = new SpeechRecognizer();
      Grammar testGrammar = new Grammar(new GrammarBuilder("this is a test"));
      sr.LoadGrammarAsync(testGrammar);
      sr.EmulateRecognizeAsync("this is a test");
      Close();
    }

    SpeechRecognizer sr;
  }
}