SpeechRecognizer.AudioPosition SpeechRecognizer.AudioPosition SpeechRecognizer.AudioPosition SpeechRecognizer.AudioPosition Property

定義

音声認識エンジンに入力を提供しているデバイスによって生成されているオーディオ ストリーム内の現在の位置を取得します。Gets the current location in the audio stream being generated by the device that is providing input to the speech recognizer.

public:
 property TimeSpan AudioPosition { TimeSpan get(); };
public TimeSpan AudioPosition { get; }
member this.AudioPosition : TimeSpan
Public ReadOnly Property AudioPosition As TimeSpan

プロパティ値

入力を受け取った音声認識エンジンのオーディオ入力ストリームの現在の位置。The current location in the speech recognizer's audio input stream through which it has received input.

次の例では、共有音声認識エンジンがディクテーション文法を使用して音声入力を照合します。In the following example, the shared speech recognizer uses a dictation grammar to match speech input. このSpeechDetectedイベントのハンドラーはAudioPosition、音声認識エンジンが入力RecognizerAudioPosition時に音声を検出したときに、、、およびAudioLevelをコンソールに書き込みます。A handler for the SpeechDetected event writes to the console the AudioPosition, RecognizerAudioPosition, and AudioLevel when the speech recognizer detects speech at its input.

using System;  
using System.Speech.Recognition;  
  
namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognizer recognizer;  
    public static void Main(string[] args)  
    {  
  
      // Initialize a shared speech recognition engine.  
      recognizer = new SpeechRecognizer();  
  
      // Add handlers for events.  
      recognizer.LoadGrammarCompleted +=   
        new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
      recognizer.SpeechRecognized +=   
        new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
      recognizer.StateChanged +=   
        new EventHandler<StateChangedEventArgs>(recognizer_StateChanged);  
      recognizer.SpeechDetected +=   
        new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);  
  
      // Create a dictation grammar.  
      Grammar dictation = new DictationGrammar();  
      dictation.Name = "Dictation";  
  
      // Load the grammar object to the recognizer.  
      recognizer.LoadGrammarAsync(dictation);  
  
      // Keep the console window open.  
      Console.ReadLine();  
    }  
  
    // Gather information about detected speech and write it to the console.  
    static void recognizer_SpeechDetected(object sender, SpeechDetectedEventArgs e)  
    {  
      Console.WriteLine();  
      Console.WriteLine("Speech detected:");  
      Console.WriteLine("  Audio level: " + recognizer.AudioLevel);  
      Console.WriteLine("  Audio position: " + recognizer.AudioPosition);  
      Console.WriteLine("  Recognizer audio position: " + recognizer.RecognizerAudioPosition);  
    }  
  
    // Write the text of the recognition result to the console.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {   
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
  
      // Add event handler code here.  
    }  
  
    // Write the name of the loaded grammar to the console.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
    }  
  
    // Put the shared speech recognizer into "listening" mode.  
    static void recognizer_StateChanged(object sender, StateChangedEventArgs e)  
    {  
      if (e.RecognizerState != RecognizerState.Stopped)  
      {  
        recognizer.EmulateRecognizeAsync("Start listening");  
      }  
    }  
  }  
}  
  

注釈

共有認識エンジンは、デスクトップ音声認識が実行されている間、入力を受け取ります。The shared recognizer receives input while the desktop speech recognition is running.

プロパティAudioPositionは、生成されたオーディオストリーム内の入力デバイスの位置を参照します。The AudioPosition property references the input device's position in its generated audio stream. これに対し、 RecognizerAudioPositionプロパティは、オーディオ入力を処理するときの認識エンジンの位置を参照します。By contrast, the RecognizerAudioPosition property references the recognizer's position in processing audio input. これらの位置は異なる場合があります。These positions can be different. たとえば、認識結果がまだ生成されていない認識エンジンが入力を受け取った場合、 RecognizerAudioPositionプロパティの値はAudioPositionプロパティの値よりも小さくなります。For example, if the recognizer has received input for which it has not yet generated a recognition result then the value of the RecognizerAudioPosition property is less than the value of the AudioPosition property.

適用対象

こちらもご覧ください