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

(VS2102) Speech Recognition Suddenly Stopped

$
0
0
Hi,

I put together the following code to start automating some stuff on my PC and it all worked great apart from random command pickups but now it just doesnt work. it always showed in the immedaite window:
Speech.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.

All functions i used worked no problem.

Now it also shows:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll

Now the speech doesnt respond at all.

I have googled it all day and not much out there (that i understand) to resolve the issue ro what might have happened to stop it working. last thing i remember was just adding another command (i.e. if you hear this do this) in the same format all the rest are.

Here is my code (be gentle i am still very much padawan learner):
Code:

Imports System.Speech


Public Class Form1

    Dim WithEvents reco As New Recognition.SpeechRecognitionEngine

    Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted

        reco.RecognizeAsync()

    End Sub

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

        reco.SetInputToDefaultAudioDevice()
        Dim gram As New Recognition.SrgsGrammar.SrgsDocument
        Dim commandRule As New Recognition.SrgsGrammar.SrgsRule("command")
        Dim commandList As New Recognition.SrgsGrammar.SrgsOneOf("jacob start music", "jacob start go", "jacob start teamspeak", "jacob close music", "music play", "music stop", "thankyou jacob", "music next", "jacob show me the daily mail", "jacob close go", "music back", "music pause", "jacob show me hmp forums")
        commandRule.Add(commandList)
        gram.Rules.Add(commandRule)
        gram.Root = commandRule
        reco.LoadGrammar(New Recognition.Grammar(gram))

        reco.RecognizeAsync()

    End Sub



    Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized

        Select Case e.Result.Text

            Case "jacob start music"

                startmusic()

            Case "jacob start go"

                startgo()

            Case "jacob start teamspeak"

                startteamspeak()

            Case "jacob close music"

                closemusic()

            Case "music play"

                musicplay()

            Case "music stop"
                musicstop()

            Case "thankyou jacob"

                yourwelcome()

            Case "music next"

                musicskipfw()

            Case "jacob show me the daily mail"
                dailymail()

            Case "jacob close go"
                closego()

            Case "music back"
                musicskipbk()

            Case "music pause"
                musicpause()

            Case "jacob show me hmp forums"
                hmpforums()


        End Select

    End Sub

    '########## MUSIC CONTROLS #############



    'Start Winamp
    Private Sub startmusic()
        Dim pHelp As New ProcessStartInfo
        Dim synth As New Synthesis.SpeechSynthesizer
        pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
        pHelp.Arguments = "/start"
        pHelp.UseShellExecute = True
        pHelp.WindowStyle = ProcessWindowStyle.Normal
        Dim proc As Process = Process.Start(pHelp)

        synth.SpeakAsync("Started Music Player - Enjoy!")

    End Sub


    'Play
    Private Sub musicplay()
        Dim p() As Process
        Dim synth As New Synthesis.SpeechSynthesizer
        p = Process.GetProcessesByName("winamp")
        If p.Count > 0 Then
            Dim pHelp As New ProcessStartInfo
            pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
            pHelp.Arguments = "/play"
            pHelp.UseShellExecute = True
            pHelp.WindowStyle = ProcessWindowStyle.Normal
            Dim proc As Process = Process.Start(pHelp)

            synth.SpeakAsync("Playing!")
        Else
            synth.SpeakAsync("Apologies Sire, But the music player is not open")
        End If

    End Sub

    'Pause
    Private Sub musicpause()
        Dim p() As Process
        Dim synth As New Synthesis.SpeechSynthesizer
        p = Process.GetProcessesByName("winamp")
        If p.Count > 0 Then
            Dim pHelp As New ProcessStartInfo
            pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
            pHelp.Arguments = "/pause"
            pHelp.UseShellExecute = True
            pHelp.WindowStyle = ProcessWindowStyle.Normal
            Dim proc As Process = Process.Start(pHelp)

            synth.SpeakAsync("Music Paused")
        Else
            synth.SpeakAsync("Apologies Sire, But the music player is not open")
        End If


    End Sub

    'Skip Forward
    Private Sub musicskipfw()
        Dim p() As Process
        Dim synth As New Synthesis.SpeechSynthesizer
        p = Process.GetProcessesByName("winamp")
        If p.Count > 0 Then
            Dim pHelp As New ProcessStartInfo
            pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
            pHelp.Arguments = "/next"
            pHelp.UseShellExecute = True
            pHelp.WindowStyle = ProcessWindowStyle.Normal
            Dim proc As Process = Process.Start(pHelp)

            synth.SpeakAsync("Skip Forward")
        Else
            synth.SpeakAsync("Apologies Sire, But the music player is not open")
        End If

    End Sub

    'Skip Back
    Private Sub musicskipbk()
        Dim p() As Process
        Dim synth As New Synthesis.SpeechSynthesizer
        p = Process.GetProcessesByName("winamp")
        If p.Count > 0 Then
            Dim pHelp As New ProcessStartInfo
            pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
            pHelp.Arguments = "/prev"
            pHelp.UseShellExecute = True
            pHelp.WindowStyle = ProcessWindowStyle.Normal
            Dim proc As Process = Process.Start(pHelp)

            synth.SpeakAsync("Skip Back")
        Else
            synth.SpeakAsync("Apologies Sire, But the music player is not open")
        End If

    End Sub

    'Stop
    Private Sub musicstop()
        Dim p() As Process
        Dim synth As New Synthesis.SpeechSynthesizer
        p = Process.GetProcessesByName("winamp")
        If p.Count > 0 Then
            Dim pHelp As New ProcessStartInfo

            pHelp.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
            pHelp.Arguments = "/stop"
            pHelp.UseShellExecute = True
            pHelp.WindowStyle = ProcessWindowStyle.Normal
            Dim proc As Process = Process.Start(pHelp)
            synth.SpeakAsync("Playback Stopped!")
        Else
            synth.SpeakAsync("Apologies Sire, But the music player is not open")
        End If



    End Sub

    'Close Winamp
    Private Sub closemusic()
        Dim pHelp2 As New ProcessStartInfo
        Dim synth2 As New Synthesis.SpeechSynthesizer
        pHelp2.FileName = "C:\Program Files (x86)\Winamp\WACommand.exe"
        pHelp2.Arguments = "/quit"
        pHelp2.UseShellExecute = True
        pHelp2.WindowStyle = ProcessWindowStyle.Normal
        Dim proc As Process = Process.Start(pHelp2)


        synth2.SpeakAsync("Music Player Closed")
    End Sub


    '##########################################################


    '##################### GAMES ##############################

    Private Sub closego()
        Dim synth As New Synthesis.SpeechSynthesizer
        Dim p() As Process
        p = Process.GetProcessesByName("csgo")
        If p.Count > 0 Then
            Process.GetProcessesByName("csgo")(0).Kill()

            synth.SpeakAsync("Counter Strike Close Sir. Did you have fun?")
        Else
            synth.SpeakAsync("Counter Strike is not running sir")
        End If

    End Sub

    '##########################################################


    '#################### WEBSITES ############################

    Private Sub dailymail()
        Dim synth As New Synthesis.SpeechSynthesizer

        Dim pHelp2 As New ProcessStartInfo
        pHelp2.FileName = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
        pHelp2.Arguments = "www.dailymail.co.uk"
        pHelp2.UseShellExecute = True
        pHelp2.WindowStyle = ProcessWindowStyle.Normal
        Dim proc As Process = Process.Start(pHelp2)


        synth.SpeakAsync("Showing Daily mail news website")


    End Sub

    Private Sub hmpforums()
        Dim synth As New Synthesis.SpeechSynthesizer

        Dim phelp2 As New ProcessStartInfo
        phelp2.FileName = "c:\program files (x86)\google\chrome\application\chrome.exe"
        phelp2.Arguments = "http://hmp-clan.co.uk/e107_plugins/forum/forum.php"
        phelp2.UseShellExecute = True
        phelp2.WindowStyle = ProcessWindowStyle.Normal
        Dim proc As Process = Process.Start(phelp2)


        synth.SpeakAsync("showing h m p forums")


    End Sub

    '##########################################################


    '##################### GENERAL STUFF ######################

    'Thank you replies
    Private Sub yourwelcome()
        Dim synth As New Synthesis.SpeechSynthesizer
        Dim rnd As New Random
        Dim possanswers() As String = {"You're Welcome Sir!", "No Problem Sir!", "I aim to please Sire!"}

        Dim mIndex As Integer = rnd.Next(possanswers.Length)

        synth.SpeakAsync(possanswers(mIndex))
    End Sub




    Private Sub startgo()
        Dim pHelp As New ProcessStartInfo
        Dim synth As New Synthesis.SpeechSynthesizer
        pHelp.FileName = "L:\Steam\steam.exe"
        pHelp.Arguments = "-applaunch 730"
        pHelp.UseShellExecute = True
        pHelp.WindowStyle = ProcessWindowStyle.Normal
        Dim proc As Process = Process.Start(pHelp)

        synth.SpeakAsync("Starting Counter Strike Go")


    End Sub

    Private Sub startteamspeak()
        Dim p As Process = Process.Start("L:\Teamspeak\ts3client_win64.exe")
        Dim synth As New Synthesis.SpeechSynthesizer

        synth.SpeakAsync("Starting Team Speak")
    End Sub

End Class

Any help to get me back up and running would be great, i was having a lot of fun with this!

Viewing all articles
Browse latest Browse all 27349

Trending Articles



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