首页 > 解决方案 > 使用 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

标签: vbapowerpointvoice-recognition

解决方案


该错误是说:

SPERR_RECOGNIZER_NOT_FOUND 0x80045077 -2147200905 没有安装识别器。


推荐阅读