Поделиться через


SpeechRecognitionEngine.SpeechHypothesized Событие

Определение

Возникает, когда SpeechRecognitionEngine распознал слово или слова, которые могут являться нескольких составных фраз в грамматике.

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) 

Тип события

Примеры

В следующем примере распознают такие фразы, как "Отобразить список исполнителей в джазовой категории". В примере используется SpeechHypothesized событие для отображения неполных фрагментов фраз в консоли по мере их распознавания.

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

Комментарии

Создает SpeechRecognitionEngine многочисленные SpeechHypothesized события при попытке идентифицировать входную фразу. Вы можете получить доступ к тексту частично распознаваемых фраз в Result свойстве SpeechHypothesizedEventArgs объекта в обработчике SpeechHypothesized события. Как правило, обработка этих событий полезна только для отладки.

Интерфейс SpeechHypothesizedEventArgs является производным от интерфейса RecognitionEventArgs.

Дополнительные сведения см. в описании EndSilenceTimeoutAmbiguous свойства и Recognizeметодов , RecognizeAsync, EmulateRecognizeи EmulateRecognizeAsync .

При создании делегата SpeechHypothesized необходимо указать метод, обрабатывающий событие. Чтобы связать событие с обработчиком событий, нужно добавить в событие экземпляр делегата. Обработчик событий вызывается всякий раз, когда происходит событие, если делегат не удален. Дополнительные сведения о делегатах обработчика событий см. в разделе События и делегаты.

Применяется к

См. также раздел