RecognizeCompletedEventArgs.InitialSilenceTimeout プロパティ

定義

初期サイレント タイムアウトで RecognizeCompleted イベントが生成されたかどうかを示す値を取得します。Gets a value that indicates whether an initial silence timeout generated the RecognizeCompleted event.

public:
 property bool InitialSilenceTimeout { bool get(); };
public bool InitialSilenceTimeout { get; }
member this.InitialSilenceTimeout : bool
Public ReadOnly Property InitialSilenceTimeout As Boolean

プロパティ値

SpeechRecognitionEngine が、InitialSilenceTimeout プロパティで指定された時間よりも長い期間、無音だけを検出した場合は true。それ以外の場合は false.true if the SpeechRecognitionEngine has detected only silence for a longer time period than was specified by its InitialSilenceTimeout property; otherwise false.

次の例では、メソッドとSpeechRecognitionEngine.RecognizeAsyncインプロセスレコグナイザーを使用して、音声認識の文法で非同期音声認識を実行します。The following example performs asynchronous speech recognition on a speech recognition grammar, using the SpeechRecognitionEngine.RecognizeAsync method with the in-process recognizer. この例でChoicesGrammarBuilderGrammarオブジェクトとオブジェクトを使用して、オブジェクトにビルドする前に音声認識文法を作成します。The example uses Choices and GrammarBuilder objects to create the speech recognition grammar before building it into a Grammar object. SpeechRecognitionEngine.RecognizeCompletedイベントのハンドラーは、認識操作に関する情報をコンソールに出力します。A handler for the SpeechRecognitionEngine.RecognizeCompleted event outputs information about the recognition operation to the console.

using System;  
using System.Speech.Recognition;  
  
namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  
    {  
  
      // Initialize a SpeechRecognitionEngine object and set its input.  
      recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));  
      recognizer.SetInputToDefaultAudioDevice();  
  
      // Configure recognition parameters.  
      recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(5.0);  
      recognizer.BabbleTimeout = TimeSpan.FromSeconds(3.0);  
      recognizer.EndSilenceTimeout = TimeSpan.FromSeconds(1.0);  
      recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.0);  
  
      // Add a handler for the LoadGrammarCompleted event.  
      recognizer.LoadGrammarCompleted +=  
        new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
  
      // Add a handler for the RecognizeCompleted event.  
      recognizer.RecognizeCompleted +=   
        new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);  
  
      // Create a speech recognition grammar and build it into a Grammar object.  
      Choices bankingMenu = new Choices(new string[]   
      { "Access accounts", "Transfer funds", "Pay bills", "Get loan balance" });  
      GrammarBuilder banking = new GrammarBuilder(bankingMenu);  
      Grammar bankGrammar = new Grammar(banking);  
      bankGrammar.Name = "Banking Menu";  
  
      // Load the Grammar objects to the recognizer.  
      recognizer.LoadGrammarAsync(bankGrammar);  
  
      // Start asynchronous, continuous recognition.  
      recognizer.RecognizeAsync();  
  
      // Keep the console window open.  
      Console.ReadLine();  
    }  
  
    // Handle the RecognizeCompleted event.  
    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)  
    {  
      if (e.Error != null)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted, error occurred during recognition: {0}", e.Error);  
        return;  
      }  
  
      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: BabbleTimeout({0}), InitialSilenceTimeout({1}).",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
        return;  
      }  
  
      if (e.InputStreamEnded)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: AudioPosition({0}), InputStreamEnded({1}).",  
          e.AudioPosition, e.InputStreamEnded);  
      }  
  
      if (e.Result != null)  
      {  
        Console.WriteLine(  
          "RecognizeCompleted: Grammar ({0}), Text ({1}), Confidence ({2}), AudioPosition ({3}).",  
          e.Result.Grammar.Name, e.Result.Text, e.Result.Confidence, e.AudioPosition);  
      }  
  
      else  
      {  
        Console.WriteLine("RecognizeCompleted: No result.");  
      }   
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  
    // Handle the LoadGrammarCompleted event.   
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      string grammarName = e.Grammar.Name;  
      bool grammarLoaded = e.Grammar.Loaded;  
      bool grammarEnabled = e.Grammar.Enabled;  
  
      if (e.Error != null)  
      {  
        Console.WriteLine("LoadGrammar for {0} failed with a {1}.",  
        grammarName, e.Error.GetType().Name);  
  
        // Add exception handling code here.  
      }  
  
      Console.WriteLine("Grammar {0} {1} loaded and {2} enabled.", grammarName,   
        (grammarLoaded) ? "is" : "is not", (grammarEnabled) ? "is" : "is not");  
    }  
  }            
}  
  

適用対象

こちらもご覧ください