How to access Speech Recognition via Win32 API?

Viewed 134

I'm trying to update a very old VB6 program to provide Speech Recognition. I'm thinking the best way to do this is by accessing the Win32 API for Speech Recognition.

Looked for this on MS documentation. Looks like previously this would be done via the SAPI 5.3 per this question which has been deprecated and replaced by MS Agent, which itself is deprecated.

1 Answers

http://msdn.microsoft.com/en-us/library/ms720589(VS.85).aspx

The above link is old (because I used it 10 years ago), but is valid. You basically create the appropriate objects, possibly create a grammar in their format, and then create events on the RC object, below:

The below method "works", but it wasn't very impressive. Also, it led us to have to create our own MsgBox function, since we needed to automate everything... And, since you can't just tell Windows to "click" the OK button of a standard message box (unless you want to muck around even more APIs), you have to control even more aspects of your software.

It did work, but I'm not sure anyone ever used it.

Public WithEvents RC As SpSharedRecoContext
Public myGrammar, b As ISpeechRecoGrammar

Private Sub Form_Load()
    On Error GoTo EH

    Set RC = New SpSharedRecoContext

    Set myGrammar = RC.CreateGrammar
    myGrammar.CmdLoadFromFile "sol.xml", SLODynamic
    myGrammar.CmdSetRuleIdState 0, SGDSActive

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub RC_FalseRecognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)
    'Label1.Caption = "(no recognition)"
End Sub

Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
    'Label1.Caption = Result.PhraseInfo.GetText
End Sub

Private Sub RC_StartStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    'Label2.Caption = Val(StreamNumber)
End Sub
Related