SpeechRecognizer.AudioPosition Properti

Definisi

Mendapatkan lokasi saat ini di aliran audio yang dihasilkan oleh perangkat yang memberikan input ke pengenal ucapan.

C#
public TimeSpan AudioPosition { get; }

Nilai Properti

Lokasi saat ini dalam aliran input audio pengenal ucapan yang telah menerima input.

Contoh

Dalam contoh berikut, pengenal ucapan bersama menggunakan tata bahasa dikte untuk mencocokkan input ucapan. Handler untuk SpeechDetected peristiwa menulis ke konsol AudioPosition, , RecognizerAudioPositiondan AudioLevel ketika pengenal ucapan mendeteksi ucapan pada inputnya.

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

Keterangan

Pengenal bersama menerima input saat pengenalan ucapan desktop sedang berjalan.

Properti AudioPosition mereferensikan posisi perangkat input dalam aliran audio yang dihasilkan. Sebaliknya, properti mereferensikan RecognizerAudioPosition posisi pengenal dalam memproses input audio. Posisi ini bisa berbeda. Misalnya, jika recognizer telah menerima input yang belum menghasilkan hasil pengenalan RecognizerAudioPosition , maka nilai properti kurang dari nilai AudioPosition properti .

Berlaku untuk

Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Lihat juga