InitialSilenceTimeout Property

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Property InitialSilenceTimeout As TimeSpan
	Get
	Set
Visual Basic (Usage)
Dim instance As SpeechRecognitionEngine
Dim value As TimeSpan

value = instance.InitialSilenceTimeout

instance.InitialSilenceTimeout = value
C#
public TimeSpan InitialSilenceTimeout { get; set; }

Property Value

Type: System..::..TimeSpan

The duration of the interval of silence.

Remarks

Each speech recognizer has an algorithm to distinguish between silence and speech. If the recognizer input is silence during the initial silence timeout period, then the recognizer finalizes that recognition operation.

If the initial silence timeout interval is set to 0, the recognizer does not perform an initial silence timeout check. The timeout interval can be any non-negative interval. The default is 0 seconds.

Examples

The following example shows part of a console application that demonstrates basic speech recognition. The example 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 properties affect recognition operations.

C# Copy imageCopy Code
using System;
using Microsoft.Speech.Recognition;

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

      // Initialize a SpeechRecognitionEngine object.
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("en-US")))
      {

      // Create a grammar for choosing cities for a flight.
        Choices cities = new Choices(new string[] 
        { "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" });

        GrammarBuilder gb = new GrammarBuilder();
        gb.Append("I want to fly from");
        gb.Append(cities);
        gb.Append("to");
        gb.Append(cities);      

        // Create a Grammar object from the GrammarBuilder and load it to the recognizer.
        Grammar g = new Grammar(gb);
        g.Name = ("City Chooser");
        recognizer.LoadGrammarAsync(g);

        // 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();
        }
      }
    }

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

See Also