SpeechRecognitionEngine.SpeechRecognized 이벤트

정의

SpeechRecognitionEngine에서 로드하고 활성화한 어떤 Grammar 개체와 일치하는 입력을 받을 때 발생

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 Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs) 
Public Custom Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs) 

이벤트 유형

예제

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

"시카고에서 마이애미 갈"을 트리거할 같은 입력 음성는 SpeechRecognized 이벤트입니다. "Fly me Houston에서 시카고로" 라는 문구를 말하기 트리거되지는 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 메서드. , , InitialSilenceTimeoutEndSilenceTimeoutEndSilenceTimeoutAmbiguous 속성을 사용하여 음성 인식이 음성이 아닌 입력에 응답하는 BabbleTimeout방법을 수정할 수 있습니다.

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

SpeechRecognized 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 및 대리자합니다.

적용 대상

추가 정보