SpeechRecognitionEngine.SpeechRecognized 이벤트

정의

로드되고 활성화 SpeechRecognitionEngine 된 개체와 일치하는 입력을 수신할 때 Grammar 발생합니다.

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

이벤트 유형

예제

다음 예제는 음성 인식 문법을 만들고, 개체를 Grammar 생성하고, 인식을 수행하기 위해 로드하는 콘솔 애플리케이션의 SpeechRecognitionEngine 일부입니다. 이 예제에서는 음성 인식기에서 SpeechRecognitionEngine발생하는 음성 입력, 연결된 인식 결과 및 관련 이벤트를 보여 줍니다.

"시카고에서 마이애미로 날아가고 싶다"와 같은 음성 입력이 이벤트를 트리거합니다 SpeechRecognized . "휴스턴에서 시카고로 날 날아라"라는 문구는 이벤트를 트리거 SpeechRecognized 하지 않습니다.

이 예제에서는 이벤트에 대한 SpeechRecognized 처리기를 사용하여 성공적으로 인식된 구와 콘솔에 포함된 의미 체계를 표시합니다.

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 SemanticResultValue objects that contain cities and airport codes.
        SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
        SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
        SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
        SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");

        // Create a Choices object and add the SemanticResultValue objects, using
        // implicit conversion from SemanticResultValue to GrammarBuilder
        Choices cities = new Choices();
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

        // Build the phrase and add SemanticResultKeys.
        GrammarBuilder chooseCities = new GrammarBuilder();
        chooseCities.Append("I want to fly from");
        chooseCities.Append(new SemanticResultKey("origin", cities));
        chooseCities.Append("to");
        chooseCities.Append(new SemanticResultKey("destination", cities));

        // Build a Grammar object from the GrammarBuilder.
        Grammar bookFlight = new Grammar(chooseCities);
        bookFlight.Name = "Book Flight";

        // Add a handler for the LoadGrammarCompleted event.
        recognizer.LoadGrammarCompleted +=
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

        // Add a handler for the SpeechRecognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

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

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

        // Start recognition.
        recognizer.RecognizeAsync();

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

    // 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("Speech recognized:  " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);
    }
  }
}

설명

또는 RecognizeAsync 메서드 중 Recognize 하나를 사용하여 인식 작업을 시작할 수 있습니다. 인식기가 입력이 로드된 Grammar 개체 중 하나와 일치하는지 확인하면 인식을 구성할 수 있는 충분한 수준의 신뢰도로 이벤트를 발생 SpeechRecognized 합니다. Result 허용되는 SpeechRecognitionRejectedEventArgs 개체를 RecognitionResult 포함하는 속성입니다. SpeechRecognized 이벤트 처리기는 인식된 구와 신뢰도 점수가 낮은 인식 Alternates 목록을 가져올 수 있습니다.

애플리케이션에서 인스턴스를 SpeechRecognitionEngine 사용하는 경우 메서드 중 하나를 사용하여 음성 입력이 수락되거나 거부되는 신뢰도 수준을 수정할 UpdateRecognizerSetting 수 있습니다. , BabbleTimeoutInitialSilenceTimeoutEndSilenceTimeout 속성을 사용하여 음성 인식이 음성이 아닌 입력에 응답하는 EndSilenceTimeoutAmbiguous방법을 수정할 수 있습니다.

인식기가 문법과 일치하는 입력을 받으면 개체가 Grammar 해당 SpeechRecognized 이벤트를 발생시키는 경우가 있습니다. Grammar 개체의 SpeechRecognized 이벤트는 음성 인식기 SpeechRecognized 이벤트 이전에 발생합니다. 특정 문법과 관련된 모든 작업은 항상 이벤트에 대한 SpeechRecognized 처리기에서 수행해야 합니다.

대리자를 SpeechRecognized 만들 때 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 이벤트에 추가합니다. 대리자를 제거하지 않는 한 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.

적용 대상

추가 정보