So frustrating...I've been Googling all over, posted at various developer forums, but so far I can't find an answer:

The goal -- use VB.Net to write a windows forms application that responds to a limited set of voice commands after the user says a keyword, (such as "Wake Up"). I have the following code I am using from another site but I am getting an error I do not understand (nor do several others who posted comments at the same site.)

Imports System
Imports System.Data
Imports System.Deployment
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Xml
Imports SpeechLib


Public Class Form1
    Dim WithEvents RecoContext As SpSharedRecoContext
    Dim Grammar As ISpeechRecoGrammar                       'The Grammar Object so the program knows what is going on. -- Instanced Object: More Info on this later.
    Dim CharCount As Integer

    Private Sub ButtonStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStart.Click

        'The Main Recognition Object Used throughout the whole program. -- Shared Object: More Info on this later.
        Try
            If (RecoContext Is Nothing) Then

                RecoContext = New SpSharedRecoContextClass          'Create a new Reco Context Class


                Grammar = RecoContext.CreateGrammar(1)              'Setup the Grammar


                Grammar.DictationLoad(1)                            'Load the Grammar


            End If

            lblstatus.Text = "Recognition Started."

            Grammar.DictationSetState(SpeechRuleState.SGDSActive)   'Turns on the Recognition. This is Vitally important
            ButtonStart.Enabled = False
            ButtonStop.Enabled = True

        Catch ex As Exception

            MsgBox(ex.Message)


        End Try



    End Sub

    Private Sub ButtonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStop.Click
        Grammar.DictationSetState(SpeechRuleState.SGDSInactive) 'Turns off the Recognition. It will go dormant.
        lblstatus.Text = "Recognition Stopped"                  'Change the label to let the user know whats up

        'Again This is so the user doesn't go breaking things accidently
        ButtonStart.Enabled = True
        ButtonStop.Enabled = False

    End Sub
    Private Sub OnHypo(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal Result As ISpeechRecoResult) Handles RecoContext.Hypothesis

        ButtonStop.Enabled = False    'Don't allow the user to stop the recognition until it has completed.
        'The button will re-enable in the OnReco Event

        'This is so you don't kepp printing the same text over and over. It could take up just a tiny bit more processor power
        'Its good to not do un-needed things.
        If lblStatus.Text <> "Receiving" Then
            lblStatus.Text = "Receiving"
        End If
    End Sub
    'This sub is fired when the reco engine detects a set of words. This is what you want to use to print or sendkey.
    'Use this sub for the final printing of words.
    Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition

        Dim recoResult As String = Result.PhraseInfo.GetText 'Create a new string, and assign the recognized text to it.

        'This block will print to the textbox built into the program
        'If you would prefer to use the SendKeys method, Comment out this entire block. And Uncomment the SendKeys Line.
        txtBox.SelectionStart = CharCount
        txtBox.SelectedText = recoResult & " "
        CharCount = CharCount + 1 + Len(recoResult)

        'Uncomment the next line if you want to send the text to the selected window rather than constrain it to the textbox.
        'SendKeys.Send(recoResult & " ") 'This line sends the result via SendKeys to the top window.

        lblStatus.Text = "Finished Dictating"
        ButtonStop.Enabled = True
    End Sub


    
End Class

But just like some of the responders, I am getting a result of
EXCEPTION FROM HRESULT: 0X8004503A when I try to execute this line:

Grammar.DictationLoad(1)

If I had any understanding of how to create a grammer file I MIGHT be able to avoid this error completely, since I am only interested in a few voice commands (maybe 30), not the whole 60,000 word dictionary.

Please, I have posted at two other developer sites already and no one seems to have a clue. I am already at a dead end on this project and I have barely started it.

Thanks in advance for ANY assistance.

Try removing the 1.
e.g. Grammar.DictationLoad()

what is main object in voice recognition system in vb.net?

what is the main object in voice recognition application?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.