SpeechRecognitionEngine.AudioLevelUpdated 事件


SpeechRecognitionEngine 报告其音频输入的级别的时候引发。Raised when the SpeechRecognitionEngine reports the level of its audio input.

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


下面的示例将AudioLevelUpdated事件的处理程序添加SpeechRecognitionEngine到对象。The following example adds a handler for the AudioLevelUpdated event to a SpeechRecognitionEngine object. 处理程序将新的音频级别输出到控制台。The handler outputs the new audio level to the console.

private SpeechRecognitionEngine recognizer;  
// Initialize the SpeechRecognitionEngine object.   
private void Initialize()  
  recognizer = new SpeechRecognitionEngine();  
  // Add an event handler for the AudioLevelUpdated event.  
  recognizer.AudioLevelUpdated +=   
   new EventHandler<AudioLevelUpdatedEventArgs>(recognizer_AudioLevelUpdated);  
  // Add other initialization code here.  
// Write the audio level to the console when the AudioLevelUpdated event is raised.  
void recognizer_AudioLevelUpdated(object sender, AudioLevelUpdatedEventArgs e)  
  Console.WriteLine("The audio level is now: {0}.", e.AudioLevel);  


SpeechRecognitionEngine秒引发此事件多次。The SpeechRecognitionEngine raises this event multiple times per second. 引发事件的频率取决于运行应用程序的计算机。The frequency with which the event is raised depends on the computer on which the application is running.

若要在事件发生时获取音频级别,请使用AudioLevel关联AudioLevelUpdatedEventArgs的的属性。To get the audio level at the time of the event, use the AudioLevel property of the associated AudioLevelUpdatedEventArgs. 若要获取识别器的当前音频级别,请使用识别器的AudioLevel属性。To get the current audio level of the input to the recognizer, use the recognizer's AudioLevel property.

创建 AudioLevelUpdated 委托时,需要标识将要处理该事件的方法。When you create an AudioLevelUpdated delegate, you identify the method that will handle the event. 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。To associate the event with your event handler, add an instance of the delegate to the event. 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。The event handler is called whenever the event occurs, unless you remove the delegate. 有关事件处理程序委托的详细信息,请参阅事件和委托For more information about event-handler delegates, see Events and Delegates.