0

我想确保此代码在 vb 从用户接收声音时获取音频电平值,

当我运行此代码以及在另一个类中调用该函数时,我会收到一些警告。

获取声音识别码的音频电平值:

Imports System.Speech
Imports System.Speech.Recognition
Imports AxShockwaveFlashObjects.AxShockwaveFlash
Imports AxShockwaveFlashObjects

Public Class sound1
Private recognizer As New SpeechRecognitionEngine()

Dim value As Boolean

Sub recognizer_AudioLevelUpdated(ByVal sender As Object, ByVal e As AudioLevelUpdatedEventArgs)

    recognizer = New SpeechRecognitionEngine
    recognizer.LoadGrammar(New Grammar(New GrammarBuilder("just nothing")))
    ' the warning at the above line " InvalidOperationException Was unhandled - The language for the grammar does not match the language of the speech recognizer."  
    AddHandler recognizer.AudioLevelUpdated, AddressOf recognizer_AudioLevelUpdated
    recognizer.SetInputToDefaultAudioDevice()
    recognizer.RecognizeAsync(RecognizeMode.Multiple)
    value = e.AudioLevel
    Do While value > 70
        'Console.WriteLine(value)
        MessageBox.Show(value)
     Loop
     End Sub
     End Class

调用音频电平函数:

Imports System.Speech.Recognition
Imports System.Speech.Recognition.GrammarBuilder
Imports AxShockwaveFlashObjects.AxShockwaveFlash
Imports AxShockwaveFlashObjects

Public Class flashWithSound
Dim s As New sound1
Dim sender As Object
Dim e As AudioLevelUpdatedEventArgs


Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub

Private Sub AxShockwaveFlash1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxShockwaveFlash1.Enter

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    s.recognizer_AudioLevelUpdated(sender, e)
' the warning at the above line "InvalidCastException Was unhandled - couldn't convert object from type 'System.Windows.Forms.MouseEventArgs' to type 'System.Speech.Recognition.AudioLevelUpdatedEventArgs'."
End Sub

End Class

那么我该如何解决这些警告,请

4

1 回答 1

1

的事件参数与System.Speech.Recognition.AudioLevelUpdatedEventArgs不同System.Windows.Forms.MouseEventArgs。您不能让按钮单击事件AudioLevelEvent像这样处理。只需编写一个单独的子程序来处理该事件,您就可以开始了。

于 2013-10-30T00:02:34.727 回答