Bagikan melalui


SpeechRecognitionEngine.InitialSilenceTimeout Properti

Definisi

Mendapatkan atau mengatur interval waktu saat menerima input yang SpeechRecognitionEngine hanya berisi keheningan sebelum menyelesaikan pengenalan.

public:
 property TimeSpan InitialSilenceTimeout { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan InitialSilenceTimeout { get; set; }
member this.InitialSilenceTimeout : TimeSpan with get, set
Public Property InitialSilenceTimeout As TimeSpan

Nilai Properti

Durasi interval keheningan.

Pengecualian

Properti ini diatur ke kurang dari 0 detik.

Contoh

Contoh berikut menunjukkan bagian dari aplikasi konsol yang menunjukkan pengenalan ucapan dasar. Contoh mengatur BabbleTimeout properti dan InitialSilenceTimeout dari sebelum SpeechRecognitionEngine memulai pengenalan ucapan. Penangan untuk informasi peristiwa output pengenal AudioStateChanged ucapan dan RecognizeCompleted peristiwa ke konsol untuk menunjukkan bagaimana InitialSilenceTimeout properti SpeechRecognitionEngine properti memengaruhi operasi pengenalan.

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

Keterangan

Setiap pengenal ucapan memiliki algoritma untuk membedakan antara keheningan dan ucapan. Jika input pengenal diam selama periode batas waktu keheningan awal, maka pengenal menyelesaikan operasi pengenalan tersebut.

Jika interval batas waktu keheningan awal diatur ke 0, pengenal tidak melakukan pemeriksaan batas waktu keheningan awal. Interval batas waktu dapat berupa nilai non-negatif. Defaultnya adalah 0 detik.

Berlaku untuk

Lihat juga