Бөлісу құралы:


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 и RecognizeRecognizeAsyncметодах , EmulateRecognizeа также методах.EmulateRecognizeAsync

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

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

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