SpeechRecognitionEngine.SetInputToDefaultAudioDevice Method

Configures the SpeechRecognitionEngine object to receive input from the default audio device.

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

public void SetInputToDefaultAudioDevice()

The following example shows part of a console application that demonstrates basic speech recognition and accepts speech input from the system's default audio device.

using System;
using Microsoft.Speech.Recognition;

namespace SpeechRecognitionApp
  class Program
    static void Main(string[] args)

      // Create a SpeechRecognitionEngine object for the default recognizer in the en-US locale.
      using (
      SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("en-US")))

        // Create a grammar for finding services in different cities.
        Choices services = new Choices(new string[] { "restaurants", "hotels", "gas stations" });
        Choices cities = new Choices(new string[] { "Seattle", "Boston", "Dallas" });

        GrammarBuilder findServices = new GrammarBuilder("Find");

        // Create a Grammar object from the GrammarBuilder and load it to the recognizer.
        Grammar servicesGrammar = new Grammar(findServices);

        // Add a handler for the speech recognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

        // Configure the input to the speech recognizer.

        // Start asynchronous, continuous speech recognition.

        // Keep the console window open.
        while (true)

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
      Console.WriteLine("Recognized text: " + e.Result.Text);