共用方式為


SpeechRecognitionEngine.BabbleTimeout 屬性

定義

取得或設定完成辨識前 SpeechRecognitionEngine 接受只包含背景雜訊之輸入的時間間隔。

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

屬性值

時間間隔的持續時間。

例外狀況

這個屬性設定為小於 0 秒。

範例

下列範例顯示主控台應用程式的一部分,其中示範在起始語音辨識之前,先設定 BabbleTimeoutInitialSilenceTimeout 屬性 SpeechRecognitionEngine 的基本語音辨識。 語音辨識器和 AudioStateChangedRecognizeCompleted 事件輸出事件資訊的處理常式,向主控台示範屬性 SpeechRecognitionEngine 如何影響 InitialSilenceTimeout 辨識作業。

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

備註

每個語音辨識器都有一個演算法,可區分無聲和語音。 辨識器會分類為背景雜訊任何不符合任何辨識器載入和啟用語音辨識文法的初始規則的非無聲輸入。 如果辨識器只會在 Babble 逾時間隔內收到背景雜訊和無聲,則辨識器會完成該辨識作業。

如果 babble 逾時期間設定為 0,辨識器就不會執行 babble 逾時檢查。 逾時間隔可以是任何非負值。 預設值為 0 秒。

適用於

另請參閱