SpeechRecognitionEngine.AudioPosition SpeechRecognitionEngine.AudioPosition SpeechRecognitionEngine.AudioPosition SpeechRecognitionEngine.AudioPosition Property

定義

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

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 audio stream being generated by the input device.

次の例では、インプロセス音声認識エンジンは、音声入力に一致するのに口述文法を使用します。In the following example, the in-process speech recognizer uses a dictation grammar to match speech input. ハンドラーをSpeechDetectedをコンソールに出力イベント、 AudioPositionRecognizerAudioPosition、および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 SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize an in-process speech recognition engine for US English.  
      using (recognizer = new SpeechRecognitionEngine(  
        new System.Globalization.CultureInfo("en-US")))  
      {  
        recognizer.SetInputToDefaultAudioDevice();  

        // 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 and load it to the recognizer.  
        Grammar servicesGrammar = new Grammar(findServices);  
        recognizer.LoadGrammarAsync(servicesGrammar);  

        // Add handlers for events.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.SpeechDetected +=  
          new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);  

        // Start asynchronous recognition.  
        recognizer.RecognizeAsync();  
        Console.WriteLine("Starting asynchronous recognition...");  

        // 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 at the event: " + e.AudioPosition);  
      Console.WriteLine("  Current audio position: " + recognizer.AudioPosition);  
      Console.WriteLine("  Current 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("\nSpeech recognized: " + e.Result.Text);  

      // Add event handler code here.  
    }  
  }  
}  

注釈

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 within its audio input. これらの位置は、さまざまなであることができます。These positions can be different. たとえば、認識エンジンが受け取った場合どの it されていない入力が、認識結果が次の値を生成、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.

適用対象

こちらもご覧ください