前不久在百度文库上搜到一篇关于VB语音开发的文档 于是乎照模样自己做了个 但是老是会出现
事实错误 ’-2146697211(800C0005) 对象'cmdLoadFromFile'的方法'IspeechrecoGrammar' 另外 我的Microsoft speech SDK5.1工具包已经安装好了,小弟愚钝 求各位哥哥搭救 谢谢了.
代码如下:
Public WithEvents RC As SpSharedRecoContext '定义 RC为共享文本语音识别对象
Public myGrammar, b As ISpeechRecoGrammar '定义 词汇表语法对象
Private Sub Form_Load()
Set RC = New SpSharedRecoContext
Set myGrammar = RC.CreateGrammar
' RC.CreateGrammar.CmdLoadFromFile "e:\temp\sol.xml", SLODynamic
' RC.CreateGrammar.CmdSetRuleIdState 0, SGD - SActive
myGrammar.CmdLoadFromFile "e:\temp\s ol.xml", SLODynamic '//依据用户词汇表的语法规则调用语法词汇表
myGrammar.CmdSetRuleIdState 0, SGD - SActive
End Sub
Private Sub RC_FalseRecognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)
Label1.Caption = "(不可识别信息) "
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
Select Case Result.PhraseInfo.GetText
Case "kaishi"
MsgBox "现在开始运行程序"
Case "now start"
MsgBox "这是我编写的第一个语音程序,好高兴哦! "
Case "hello"
Text1.Text = "hii,你好,很高兴见到您!"
Case "now stop"
End
End Select
End Sub
不过 "e:\temp\s ol.xml" 里面的空格是不是存在?
还有最新版本是5.3 ,‘hii,你好,很高兴见到您!’,不对。