[VB6] Speech Recognition via SAPI-VBForums
Results 1 to 3 of 3

Thread: [VB6] Speech Recognition via SAPI

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    [VB6] Speech Recognition via SAPI

    This is a trivial demo of bare bones use of SAPI for speech recognition.

    The documentation can be found at MSDN:

    Automation Interfaces and Objects (SAPI 5.4)

    There is much more you can do than is shown in this tiny example, which uses the first audio input source found and uses defaults for many other things (such as free dictation).

    Code:
    Option Explicit
    
    'See "Automation Interfaces and Objects (SAPI 5.4)" at MSDN.
    
    Private WithEvents RC As SpeechLib.SpInProcRecoContext
    Private RG As SpeechLib.ISpeechRecoGrammar
    
    Private Sub Form_Load()
        With New SpeechLib.SpInprocRecognizer
            Set RC = .CreateRecoContext()
            Set .AudioInput = .GetAudioInputs().Item(0)
        End With
        With RC
            .EventInterests = SRERecognition Or SREFalseRecognition
            Set RG = .CreateGrammar()
        End With
        RG.DictationSetState SGDSActive
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            Text1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        RG.DictationSetState SGDSInactive
    End Sub
    
    Private Sub RC_FalseRecognition( _
        ByVal StreamNumber As Long, _
        ByVal StreamPosition As Variant, _
        ByVal Result As SpeechLib.ISpeechRecoResult)
    
        With Text1
            .SelStart = &H7FFF
            .SelText = "False Rec: "
            .SelText = Result.PhraseInfo.GetText()
            .SelText = vbNewLine
        End With
    End Sub
    
    Private Sub RC_Recognition( _
        ByVal StreamNumber As Long, _
        ByVal StreamPosition As Variant, _
        ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
        ByVal Result As SpeechLib.ISpeechRecoResult)
    
        With Text1
            .SelStart = &H7FFF
            .SelText = "Rec: "
            .SelText = Result.PhraseInfo.GetText()
            .SelText = vbNewLine
        End With
    End Sub
    Name:  sshot.png
Views: 199
Size:  1.3 KB

    SAPI 5.4 requires the dying Windows 7 or later. SAPI 5.3 is highly compatible on the dead Windows Vista. Those are part of Windows and preinstalled. You may limp along even on the dead Windows XP, 98, 2000, etc. if you install the SAPI 5.1 SDK. SAPI 5.2 was a special release only used on an old MS Speech Server product.
    Attached Files Attached Files

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,721

    Re: [VB6] Speech Recognition via SAPI

    Man, I remember playing with this stuff so many years ago when MS offered it up. Pain to use at that time because you had to train the speech engine for you and if the mike wasn't close enough -- good luck. Maybe it's gotten a lot better. I do remember writing a sample project that activated mouse actions, like move and click and also opening preset apps like Windows explorer, IE, etc.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,875

    Re: [VB6] Speech Recognition via SAPI

    True, there is no magic.

    If you don't do the training then recognition can be poor. A big part of having the mic close is to overcome echos and background noises.

    I'm not sure that it is viable or we'd see it used a lot more. We usually don't have good microphones positioned well enough for this. I think it is better, but probably only by inches.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.