I put together a simple speech recognizer. It works fine, but when I click the X to close it, it takes forever to unload... can I do anything about it?

Dim WithEvents RecoContext As SpInProcRecoContext 'RC
Dim Grammar As ISpeechRecoGrammar
Dim Recognizer As SpInprocRecognizer
Private Sub Form_Unload(Cancel As Integer)
    Set RecoContext = Nothing 'these did not work =(
    Set Grammar = Nothing ' =(
    Set Recognizer = Nothing ' =(
End Sub
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(0, -1, True)
    
    Select Case strText
        Case "calculator"
            MsgBox "calc.exe"
    End Select
End Sub
Private Sub Form_Load()
    Dim Category As SpObjectTokenCategory
    Dim Token As SpObjectToken
    
    Set RecoContext = New SpInProcRecoContext
    Set Recognizer = RecoContext.Recognizer
    Set Grammar = RecoContext.CreateGrammar(1)
    
    Grammar.CmdLoadFromFile App.Path & "\grammar.xml", SLOStatic
    Grammar.DictationSetState SGDSInactive
    Grammar.CmdSetRuleIdState 1, SGDSActive
    
    Set Category = New SpObjectTokenCategory
    Category.SetId SpeechCategoryAudioIn
    Set Token = New SpObjectToken
    Token.SetId Category.Default()
    Set Recognizer.AudioInput = Token
End Sub

thanks =)

Don't know if it will help... but do your object have a close method or other house keeping call you can make before you set them to nothing? Or if you are worried about your form staying up, just add a me.hide before you do your current code.

Good Luck

strange....it only seems to happen sometimes...it will hang for like 3 or 4 seconds on closing..

this seems to help, if I stick it in Form_Unload, so thanks =) I think it may be that the recognition has a timeout or something...I tried snapping my fingers and making some noise before closing it and it froze for a few seconds...LoL forgot the doevents? =/

'SpInProcRecoContext
RecoContext.Pause

I stuck one of these in there just to make sure too:
Grammar.CmdSetRuleIdState 1, SGDSInactive

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.