SpeechRecognitionEngine.BabbleTimeout Property

Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only background noise, before finalizing recognition.

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

public TimeSpan BabbleTimeout { get; set; }

Property Value

Type: System.TimeSpan
The duration of the time interval.

ExceptionCondition
ArgumentOutOfRangeException

This property is set to less than 0 seconds.

Each speech recognizer has an algorithm to distinguish between silence and speech. The recognizer classifies as background noise any non-silence input that does not match the initial rule of any of the recognizer's loaded and enabled speech recognition grammars. If the recognizer receives only background noise and silence within the babble timeout interval, then the recognizer finalizes that recognition operation.

If the babble timeout period is set to 0, the recognizer does not perform a babble timeout check. The timeout interval can be any non-negative value. The default is 0 seconds.

The following example shows part of a console application that demonstrates basic speech recognition that sets the BabbleTimeout and InitialSilenceTimeout properties of a SpeechRecognitionEngine before initiating speech recognition. Handlers for the speech recognizer's AudioStateChanged and RecognizeCompleted events output event information to the console to demonstrate how the InitialSilenceTimeout properties of a SpeechRecognitionEngine affect recognition operations.

using System;
using System.Speech.Recognition;

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

      // Initialize an in-process speech recognizer.
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("en-US")))
      {
        // Load a Grammar object.
        recognizer.LoadGrammar(CreateServicesGrammar("FindServices"));

        // Add event handlers.
        recognizer.AudioStateChanged +=
          new EventHandler<AudioStateChangedEventArgs>(
            AudioStateChangedHandler);
        recognizer.RecognizeCompleted +=
          new EventHandler<RecognizeCompletedEventArgs>(
            RecognizeCompletedHandler);

        // Configure input to the speech recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(3);
        recognizer.BabbleTimeout = TimeSpan.FromSeconds(2);
        recognizer.EndSilenceTimeout = TimeSpan.FromSeconds(1);
        recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5);

        Console.WriteLine("BabbleTimeout: {0}", recognizer.BabbleTimeout);
        Console.WriteLine("InitialSilenceTimeout: {0}", recognizer.InitialSilenceTimeout);
        Console.WriteLine("EndSilenceTimeout: {0}", recognizer.EndSilenceTimeout);
        Console.WriteLine("EndSilenceTimeoutAmbiguous: {0}", recognizer.EndSilenceTimeoutAmbiguous);
        Console.WriteLine();

        // Start asynchronous speech recognition.
        recognizer.RecognizeAsync(RecognizeMode.Single);

        // Keep the console window open.
        while (true)
        {
          Console.ReadLine();
        }
      }
    }

    // Create a grammar and build it into a Grammar object. 
    static Grammar CreateServicesGrammar(string grammarName)
    {
      
      // 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");
      findServices.Append(services);
      findServices.Append("near");
      findServices.Append(cities);

      // Create a Grammar object from the GrammarBuilder..
      Grammar servicesGrammar = new Grammar(findServices);
      servicesGrammar.Name = ("FindServices");
      return servicesGrammar;
    }

    // Handle the AudioStateChanged event.
    static void AudioStateChangedHandler(
      object sender, AudioStateChangedEventArgs e)
    {
      Console.WriteLine("AudioStateChanged ({0}): {1}",
        DateTime.Now.ToString("mm:ss.f"), e.AudioState);
    }

    // Handle the RecognizeCompleted event.
    static void RecognizeCompletedHandler(
      object sender, RecognizeCompletedEventArgs e)
    {
      Console.WriteLine("RecognizeCompleted ({0}):",
        DateTime.Now.ToString("mm:ss.f"));

      string resultText;
      if (e.Result != null) { resultText = e.Result.Text; }
      else { resultText = "<null>"; }

      Console.WriteLine(
        " BabbleTimeout: {0}; InitialSilenceTimeout: {1}; Result text: {2}",
        e.BabbleTimeout, e.InitialSilenceTimeout, resultText);
      if (e.Error != null)
      {
        Console.WriteLine(" Exception message: ", e.Error.Message);
      }

      // Start the next asynchronous recognition operation.
      ((SpeechRecognitionEngine)sender).RecognizeAsync(RecognizeMode.Single);
    }
  }
}

.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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft