vba - 使用 VBA 宏在 PowerPoint 中进行语音识别
问题描述
一周前,我有一个演示文稿,我正在使用 VBA 的语音识别制作一个 AI。它工作得很好(我从这个网站上拿了代码),直到有一天我要再次测试它但它没有工作。它返回一个错误
“运行时错误'70':权限被拒绝”
我检查了我的麦克风和网站中提到的所需的 VBA 参考。然后我去了我从中获取代码的站点,我看到了不同版本的代码(公共,共享......),当我运行它时,出现另一个错误
“运行时错误‘-2147200905 (80045077)’:自动化错误”
所以有人可以帮助我,代码曾经可以工作,我没有改变任何东西。这是代码:
Option Explicit
Dim WithEvents RC As SpInProcRecoContext
Dim Recognizer As SpInprocRecognizer
Dim myGrammar As ISpeechRecoGrammar
Private Sub CommandButton1_Click()
'On Error GoTo EH
Set RC = New SpInProcRecoContext
Set Recognizer = RC.Recognizer
Set myGrammar = RC.CreateGrammar
myGrammar.DictationSetState SGDSActive
Dim Category As SpObjectTokenCategory
Set Category = New SpObjectTokenCategory
Category.SetId SpeechCategoryAudioIn
Dim Token As SpObjectToken
Set Token = New SpObjectToken
Token.SetId Category.Default()
Set Recognizer.AudioInput = Token
'EH:
' If Err.Number Then ShowErrMsg
End Sub
Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
On Error GoTo EH
TextBox1.text = Result.PhraseInfo.GetText
EH:
If Err.Number Then ShowErrMsg
End Sub
Private Sub ShowErrMsg()
' Declare identifiers:
Const NL = vbNewLine
Dim T As String
T = "Desc: " & Err.Description & NL
T = T & "Err #: " & Err.Number
MsgBox T, vbExclamation, "Run-Time Error"
'End
End Sub
'### Second version of the code (Shared, Public...)
Option Explicit
Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar
Private Sub CommandButton1_Click()
'On Error GoTo EH
Set RC = New SpSharedRecoContext
Set myGrammar = RC.CreateGrammar
myGrammar.DictationSetState SGDSActive
'EH:
'If Err.Number Then ShowErrMsg
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
Private Sub ShowErrMsg()
' Declare identifiers:
Const NL = vbNewLine
Dim T As String
T = "Desc: " & Err.Description & NL
T = T & "Err #: " & Err.Number
MsgBox T, vbExclamation, "Run-Time Error"
End
End Sub
解决方案
该错误是说:
SPERR_RECOGNIZER_NOT_FOUND 0x80045077 -2147200905 没有安装识别器。
推荐阅读
- scripting - 在 vSphere 中创建 VM 的 Ansible 剧本
- c# - winform中控制控件之间距离的问题
- google-apps-script - 需要帮助更改谷歌表格脚本中的单元格值以匹配另一个单元格
- python - 导入线性代数 Numpy
- javascript - 在 Vue 中渲染多个组件时显示加载
- python - 如何使用套接字、pickle 和 OpenCV 使用 Python 流式传输网络摄像头?
- xcode - 如何从终端启动多个 Xcode 模拟器?
- reactjs - Material-UI:Select 组件不接受 Fragment 作为子组件。考虑提供一个数组
- javascript - 使用带有导入的 JavaScript NPM 包
- html - 如何动画展开/收缩而不是向上/向下