最近我一直在尝试为学校创建一个聊天机器人,我想要的一个功能是语音识别。遗憾的是,由于VB6的弃用性,很少有关于使用SAPI进行VB6语音识别的教程,而且根本没有用于实现自由语言的教程(简单地说没有语法设置并将语音转换为文本)。
答案 0 :(得分:1)
Automation Interfaces and Objects (SAPI 5.4)有文档。
琐碎的例子:
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