Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

Simple Speech Recognition

$
0
0
I made a huge project and now i want to implement speech recognition but it doesnt work the way i want it. i have a simple example, if you guys can help me here, i can reflect this idea on my project.

Lets assume we have form1 and form2. At the beginning form1 appears and when i say "YES" then form1 should get closed and form2 should appear. Now when i say "NO" form2 should get closed and form1 should appear. and i want to repeat it as much as I want.

In my code I cant repeat it as much as I want. if i say "Yes", form2 appears. but when i say no then nothing happens! I dnt know what i did wrong. Can someone pls provide me a code where i can say as much as I want "yes" and "no" which makes either form1 or form2 appear.



Form1
Code:

Imports System.Speech.Recognition
Imports System.Threading
Imports System.Globalization
Public Class Form1
    Dim recog As New SpeechRecognizer
    Dim gram As Grammar

    Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs)
    Public Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs)

    Dim wordlist As String() = New String() {"Yes"}

    Public Sub recevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs)


        If (e.Result.Text = "Yes") Then
            Form2.Visible = True


        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.Visible = False
        Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")

        Dim words As New Choices(wordlist)
        gram = New Grammar(New GrammarBuilder(words))
        recog.LoadGrammar(gram)

        AddHandler recog.SpeechRecognized, AddressOf Me.recevent
   
        recog.Enabled = True
    End Sub
End Class



Form2
Code:

Imports System.Speech.Recognition
Imports System.Threading
Imports System.Globalization
Public Class Form2
    Dim recog As New SpeechRecognizer
    Dim gram As Grammar

    Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs)
    Public Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs)

    Dim wordlist As String() = New String() {"Yes"}

    Public Sub recevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs)


        If (e.Result.Text = "Yes") Then
            Form1.Visible = True


        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form1.Visible = False
        Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")

        Dim words As New Choices(wordlist)
        gram = New Grammar(New GrammarBuilder(words))
        recog.LoadGrammar(gram)

        AddHandler recog.SpeechRecognized, AddressOf Me.recevent
   
        recog.Enabled = True
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>