SpeechRecoContext AudioLevel Event

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoContext Events

AudioLevel Event


The AudioLevel event occurs when the SAPI audio object detects a change in audio level.

The AudioLevel event is the only speech recognition event in SAPI automation that is not set by default. If this event is needed, it must be explicitly set with EventInterests.


SpeechRecoContext.AudioLevel(
     StreamNumber As Long,
     StreamPosition As Variant,
     AudioLevel As Long
)

Parameters

StreamNumber
Specifies the stream number.
StreamPosition
Specifies the position within the stream.
AudioLevel
Specifies the AudioLevel.

Example

The following Visual Basic form code demonstrates the use of the AudioLevel event. The application displays the audio level of the speaker's voice as well as the text of a successful recognition. The value of the speaker's voice is shown as both a numeric value as well as a histogram.

To run this code, create a form with the following controls:

  • Two labels called Label1 and Label2
  • Paste this code into the Declarations section of the form.

    The Form_Load procedure creates and activates a dictation grammar. Because the AudioLevel event is not set by default, it must be explicitly set with EventInterests. In this case, EventInterests is reset for only two events, with a Recognition as the second one.

    Public WithEvents RC As SpSharedRecoContext
    Public myGrammar As ISpeechRecoGrammar
    
    Private Sub Form_Load()
        Set RC = New SpSharedRecoContext
        
        Set myGrammar = RC.CreateGrammar
        myGrammar.DictationSetState SGDSActive
        
        RC.EventInterests = SRERecognition + SREAudioLevel
    End Sub
    
    Private Sub RC_AudioLevel(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal AudioLevel As Long)
        Label2.Caption = Val(AudioLevel)
        
        Label2.Caption = Label2.Caption & vbCrLf
        
        For i = 1 To AudioLevel
            Label2.Caption = Label2.Caption & "*"
        Next
    End Sub
    
    Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
        Label1.Caption = Result.PhraseInfo.GetText
    End Sub