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).
![Name: sshot.png
Views: 68
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.
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
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.