SpeechRecognizer.AudioPosition Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan lokasi saat ini di aliran audio yang dihasilkan oleh perangkat yang memberikan input ke pengenal ucapan.
public:
property TimeSpan AudioPosition { TimeSpan get(); };
public TimeSpan AudioPosition { get; }
member this.AudioPosition : TimeSpan
Public ReadOnly Property AudioPosition As TimeSpan
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 .