0

vb が user からサウンドを受信したときにオーディオ レベル値を取得するために、このコードを保証したいと思います。

このコードを実行するとき、および別のクラスで関数を呼び出すときに警告が表示されます。

音声認識コードの音声レベル値を取得:

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 に答える