#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Unhappy I get a user-defined type not defined error when trying to compile this. please help


    Option Explicit

    Dim WithEvents RecoContext As SpSharedRecoContext
    Dim Grammar As ISpeechRecoGrammar
    Dim Voice As SpVoice
    Dim m_bRecoRunning As Boolean
    Dim m_cChars As Integer


    Private Sub Form_Load()
    SetState False
    m_cChars = 0
    Set Voice = New SpVoice
    Timer1.Enabled = True
    End Sub

    Private Sub btnStart_Click()
    Debug.Assert Not m_bRecoRunning

    ' Initialize recognition context object and grammar object, then
    ' start dictation
    If (RecoContext Is Nothing) Then
    Debug.Print "Initializing SAPI reco context object..."
    Set RecoContext = New SpSharedRecoContext
    Set Grammar = RecoContext.CreateGrammar(1)
    Grammar.Dictationload
    End If

    Grammar.DictationSetState SGDSActive
    SetState True
    End Sub

    Private Sub btnStop_Click()
    Debug.Assert m_bRecoRunning
    Grammar.DictationSetState SGDSInactive
    SetState False
    End Sub

    ' This function handles Recognition event from the reco context object.
    ' Recognition event is fired when the speech recognition engines recognizes
    ' a sequences of words.
    Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechRecognitionType, _
    ByVal Result As ISpeechRecoResult _
    )
    Dim strText As String
    strText = Result.PhraseInfo.GetText
    Debug.Print "Recognition: " & strText & ", " & _
    StreamNumber & ", " & StreamPosition

    ' Append the new text to the text box, and add a space at the end of the
    ' text so that it looks better
    txtSpeech.SelStart = m_cChars
    txtSpeech.SelText = strText & " "
    m_cChars = m_cChars + 1 + Len(strText)

    Debug.Assert m_bRecoRunning
    Grammar.DictationSetState SGDSInactive
    SetState False
    Voice.Speak strText
    txtSpeech.Text = ""

    Debug.Print "Initializing SAPI reco context object..."
    Set RecoContext = New SpSharedRecoContext
    Set Grammar = RecoContext.CreateGrammar(1)
    Grammar.Dictationload
    Grammar.DictationSetState SGDSActive
    SetState True


    End Sub

    ' This function handles the state of Start and Stop buttons according to
    ' whether dictation is running.
    Private Sub SetState(ByVal bNewState As Boolean)
    m_bRecoRunning = bNewState
    btnStart.Enabled = Not m_bRecoRunning
    btnStop.Enabled = m_bRecoRunning
    End Sub
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,442
    Rep Power
    4539
    What version of vb?

    Where in the code does the error occur?

    Please use forum CODE tags when posting code.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0
    VB 6.0
    thanks a million
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0
    Dim Grammar As ISpeechRecoGrammar
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,442
    Rep Power
    4539
    Originally Posted by Onokpasa Aghogh
    Dim Grammar As ISpeechRecoGrammar
    It sounds like whatever object provides ISpeechRecoGrammar isn't installed or properly registered on your computer, or isn't available to your code because of some other issue like permissions.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo