Voice Command Example (Voice Command Webbrowser)

Posts 1–13 of 13 · Page 1 of 1
Voice Command Example (Voice Command Webbrowser)
First you need to add a system.speech reference

Now declare your Reference
Code:
Imports System.Speech
Now we are going to declare this into memory outside of sub.
Code:
Dim gram As New System.Speech.Recognition.DictationGrammar()
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
Now we are going to our Voice Commands
Code:
 reco.SetInputToDefaultAudioDevice()
        Dim gram As New Recognition.SrgsGrammar.SrgsDocument
        Dim Rule As New Recognition.SrgsGrammar.SrgsRule("Rule")
        Dim List As New Recognition.SrgsGrammar.SrgsOneOf("Back", "Forward", "refresh", "Set as Homepage", "Google", "Go to Homepage")
        Dim Items As New Recognition.SrgsGrammar.SrgsText
        Rule.Add(List)
        gram.Rules.Add(Rule)
        gram(dot)root = Rule
'MPGH wont let me type Gram   (.)   root  
        reco.LoadGrammar(New Recognition.Grammar(gram))
        reco.RecognizeAsync()
Now to program the Voice Commands (For our homepage I did it by going to settings, Type: String, Scope: User, Name: HomePageURL)
Code:
Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
        Dim homepage As String = My.Settings.HomePageUrl
        Select Case e.Result.Text
            Case "refresh"
                WebBrowser1.Refresh()
            Case "Back"
                WebBrowser1.GoBack()
            Case "Forward"
                WebBrowser1.GoForward()
            Case "Set as Homepage"
                My.Settings.HomePageUrl = WebBrowser1.Url.ToString
                My.Settings.Save()
                MsgBox("New HomePage:" & homepage)
            Case "Google"
                WebBrowser1.Navigate("http://google.com")
            Case "Go to Homepage"
                WebBrowser1.Navigate(homepage)
        End Select
(take note this is not proper handling, I am simply doing this improperly for the sake of not giving a fuck)

And now we finish handling our Speech recognizer.
Code:
 Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
        reco.RecognizeAsync()
    End Sub

Now you have a Voice Command Webbrowser without the need of any buttons (assuming you have a mic or a headset).
Huh, I didn't know voice commands was that simple, nice job.
When I import the Speech i got this error:

Warning 1 Namespace or type specified in the Imports 'System.Speech' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

Then, when i put these lines of code:
Code:
Dim gram As New System.Speech.Recognition.DictationGrammar()
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
I got these errors:

Error 2 Type 'System.Speech.Recognition.DictationGrammar' is not defined.
Error 3 Type 'Recognition.SpeechRecognitionEngine' is not defined.

Do I need some SDK or what?
Quote Originally Posted by Sixx93 View Post
When I import the Speech i got this error:

Warning 1 Namespace or type specified in the Imports 'System.Speech' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

Then, when i put these lines of code:
Code:
Dim gram As New System.Speech.Recognition.DictationGrammar()
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
I got these errors:

Error 2 Type 'System.Speech.Recognition.DictationGrammar' is not defined.
Error 3 Type 'Recognition.SpeechRecognitionEngine' is not defined.

Do I need some SDK or what?
If you did everything correctly and get this then

Maybe, you might need to be on .Net framework 4.0 too but im not sure.

http://www.microsoft.com/en-us/downl....aspx?id=10121ⓘ
Quote Originally Posted by unknownartist0 View Post
If you did everything correctly and get this then

Maybe, you might need to be on .Net framework 4.0 too but im not sure.

Download Speech SDK 5.1 from Official Microsoft Download Center
I'm on framework 4.5 .-.

I'm trying this speech SDK

---------- Post added at 10:54 AM ---------- Previous post was at 10:42 AM ----------

Have I to add the SDK in the project references?

Because I've installed the SDK but I still get the error
Immagine.png953 KB · 8 downloads
Quote Originally Posted by Sixx93 View Post
I'm on framework 4.5 .-.

I'm trying this speech SDK

---------- Post added at 10:54 AM ---------- Previous post was at 10:42 AM ----------

Have I to add the SDK in the project references?

Because I've installed the SDK but I still get the error

Don't post attatchment images, just go by URL and uncheck the remote url thing.

Did you add the reference? Ope up your project files, then go to References, then add Speech.
ok, I've added the references and now I don't get any errors... But when I try to run the app, on the line:
Code:
reco.SetInputToDefaultAudioDevice()
I got this:

A first chance exception of type 'System.PlatformNotSupportedException' occurred in System.Speech.dll


This is the source:

Code:
Imports System.Speech
Public Class Form1
    Dim gram As New System.Speech.Recognition.DictationGrammar()
    Dim WithEvents reco As New Recognition.SpeechRecognitionEngine

    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 Rule As New Recognition.SrgsGrammar.SrgsRule("Rule")
        Dim List As New Recognition.SrgsGrammar.SrgsOneOf("Back", "Forward", "refresh", "Set as Homepage", "Google", "Go to Homepage")
        Dim Items As New Recognition.SrgsGrammar.SrgsText
        Rule.Add(List)
        gram.Rules.Add(Rule)
        gram****ot = Rule

        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 "refresh"
                MsgBox("refresh")
            Case "Back"
                MsgBox("Back")
            Case "Forward"
                MsgBox("forward")
            Case "Set as Homepage"
                MsgBox("Set as Homepage")
            Case "Google"
                MsgBox("Google")
            Case "Go to Homepage"
                MsgBox("Go to Homepage")
        End Select
    End Sub
    Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
        reco.RecognizeAsync()
    End Sub
End Class
Quote Originally Posted by Sixx93 View Post
ok, I've added the references and now I don't get any errors... But when I try to run the app, on the line:
Code:
reco.SetInputToDefaultAudioDevice()
I got this:

A first chance exception of type 'System.PlatformNotSupportedException' occurred in System.Speech.dll


This is the source:

Code:
Imports System.Speech
Public Class Form1
    Dim gram As New System.Speech.Recognition.DictationGrammar()
    Dim WithEvents reco As New Recognition.SpeechRecognitionEngine

    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 Rule As New Recognition.SrgsGrammar.SrgsRule("Rule")
        Dim List As New Recognition.SrgsGrammar.SrgsOneOf("Back", "Forward", "refresh", "Set as Homepage", "Google", "Go to Homepage")
        Dim Items As New Recognition.SrgsGrammar.SrgsText
        Rule.Add(List)
        gram.Rules.Add(Rule)
        gram****ot = Rule

        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 "refresh"
                MsgBox("refresh")
            Case "Back"
                MsgBox("Back")
            Case "Forward"
                MsgBox("forward")
            Case "Set as Homepage"
                MsgBox("Set as Homepage")
            Case "Google"
                MsgBox("Google")
            Case "Go to Homepage"
                MsgBox("Go to Homepage")
        End Select
    End Sub
    Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
        reco.RecognizeAsync()
    End Sub
End Class
Do you even know what your doing?
Try using "try statements"

Maybe try rewriting your own method. I usually c&p then I think of a better and more CPU friendly later.
Unless your a fan boy of c&p.

Anyways have fun with what your doing..
Quote Originally Posted by wut12345 View Post
Do you even know what your doing?
Try using "try statements"

Maybe try rewriting your own method. I usually c&p then I think of a better and more CPU friendly later.
Unless your a fan boy of c&p.

Anyways have fun with what your doing..
I'm asking because I'm trying to learn something new... If you are here only to post something to increase your post counter (like you're doing in every thread, posting answers un-needed like this one )
Quote Originally Posted by wut12345 View Post
I like dis.
or

Quote Originally Posted by wut12345 View Post
1+3+3=7 1337

then go somewhere else.
Quote Originally Posted by wut12345 View Post
Do you even know what your doing?
Try using "try statements"

Maybe try rewriting your own method. I usually c&p then I think of a better and more CPU friendly later.
Unless your a fan boy of c&p.

Anyways have fun with what your doing..
I don't care If I handle things correctly, I don't care if this is a good method, I've wrote 'perfect' methods before on my own preknowledge so I could give a shit less about an Example, of using the Speech reference, I had this idea way before I knew there was a reference to use in Visual studio for speech/audio recognition.
Quote Originally Posted by Sixx93 View Post
I'm asking because I'm trying to learn something new... If you are here only to post something to increase your post counter (like you're doing in every thread, posting answers un-needed like this one )

or





then go somewhere else.
No need to get mad.

---------- Post added at 09:12 AM ---------- Previous post was at 09:03 AM ----------

Quote Originally Posted by unknownartist0 View Post
I don't care If I handle things correctly, I don't care if this is a good method, I've wrote 'perfect' methods before on my own preknowledge so I could give a shit less about an Example, of using the Speech reference, I had this idea way before I knew there was a reference to use in Visual studio for speech/audio recognition.
Nope your method is bad.
I'm not getting mad... I mean, if you don't want to help, then don't post useless things :\
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us