SpeechRecognizer.AudioLevelUpdated 事件

定义

当共享识别器报告其音频输入的级别时发生。Occurs when the shared recognizer reports the level of its audio input.

public:
 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事件的处理程序添加SpeechRecognizer到对象。The following example adds a handler for the AudioLevelUpdated event to a SpeechRecognizer object. 处理程序将新的音频级别输出到控制台。The handler outputs the new audio level to the console.

private SpeechRecognizer recognizer;  
  
// Initialize the SpeechRecognizer object.   
private void Initialize()  
{  
  recognizer = new SpeechRecognizer();  
  
  // 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);  
}  

注解

识别器每秒多次引发此事件。The recognizer 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 a delegate for an AudioLevelUpdated event, 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.

适用于

另请参阅