Sdílet prostřednictvím


SpeechRecognitionEngine.SpeechHypothesized Událost

Definice

Vyvolá se, SpeechRecognitionEngine když rozpozná slovo nebo slova, která mohou být součástí více úplných frází v gramatice.

public:
 event EventHandler<System::Speech::Recognition::SpeechHypothesizedEventArgs ^> ^ SpeechHypothesized;
public event EventHandler<System.Speech.Recognition.SpeechHypothesizedEventArgs> SpeechHypothesized;
member this.SpeechHypothesized : EventHandler<System.Speech.Recognition.SpeechHypothesizedEventArgs> 
Public Custom Event SpeechHypothesized As EventHandler(Of SpeechHypothesizedEventArgs) 

Event Type

Příklady

Následující příklad rozpoznává fráze jako "Zobrazení seznamu umělců v kategorii jazz". Příklad používá událost k SpeechHypothesized zobrazení neúplných fragmentů frází v konzole při jejich rozpoznání.

using System;
using System.Speech.Recognition;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize an in-process speech recognition engine.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine())
      {

        // Create a grammar.
        //  Create lists of alternative choices.
        Choices listTypes = new Choices(new string[] { "albums", "artists" });
        Choices genres = new Choices(new string[] {
          "blues", "classical", "gospel", "jazz", "rock" });

        //  Create a GrammarBuilder object and assemble the grammar components.
        GrammarBuilder mediaMenu = new GrammarBuilder("Display the list of");
        mediaMenu.Append(listTypes);
        mediaMenu.Append("in the");
        mediaMenu.Append(genres);
        mediaMenu.Append("category.");

        //  Build a Grammar object from the GrammarBuilder.
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);
        mediaMenuGrammar.Name = "Media Chooser";

        // Attach event handlers.
        recognizer.LoadGrammarCompleted +=
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
        recognizer.SpeechHypothesized +=
          new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);

        // Load the grammar object to the recognizer.
        recognizer.LoadGrammarAsync(mediaMenuGrammar);

        // Set the input to the recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        // Start asynchronous recognition.
        recognizer.RecognizeAsync();

        // Keep the console window open.
        Console.ReadLine();
      }
    }

    // Handle the SpeechHypothesized event.
    static void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
    {
      Console.WriteLine("Speech hypothesized: " + e.Result.Text);
    }

    // Handle the LoadGrammarCompleted event.
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
    {
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
      Console.WriteLine();
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine();
      Console.WriteLine("Speech recognized: " + e.Result.Text);
    }
  }
}

Poznámky

Při SpeechRecognitionEngine pokusu o identifikaci vstupní fráze vygeneruje řadu SpeechHypothesized událostí. Můžete získat přístup k textu částečně rozpoznaných frází ve Result vlastnosti objektu SpeechHypothesizedEventArgs v obslužné rutině SpeechHypothesized události. Zpracování těchto událostí je obvykle užitečné pouze pro ladění.

SpeechHypothesizedEventArgs je odvozeno od RecognitionEventArgs.

Další informace najdete ve EndSilenceTimeoutAmbiguous vlastnosti a Recognizemetodách , RecognizeAsyncEmulateRecognize, aEmulateRecognizeAsync.

Při vytváření delegáta SpeechHypothesized identifikujete metodu, která bude událost zpracovávat. Pokud chcete událost přidružit k obslužné rutině události, přidejte do události instanci delegáta. Obslužná rutina události je volána při každém výskytu události, dokud neodeberete delegáta. Další informace o delegátech obslužné rutiny událostí najdete v tématu Události a delegáti.

Platí pro

Viz také