需要运行由Microsoft编写的虚拟VBA,SAPI代码,但不清楚如何使用参数调用这些子例程

问题描述 投票:0回答:1

以下代码来自URL:https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms720590(v=vs.85)

该页面确实试图讲述它,但它很模糊。以下代码示例使用in process(或InProc)识别器表示一个简单但功能强大的识别应用程序。它使用听写语法并允许自由听写。注释行指的是可能显示信息的形式中的假设标签。要查看已识别的短语,请添加一个名为Label1的标签。当然,您可以根据需要修改此应用程序以满足您自己的要求。在运行应用程序之前,必须包含语音参考。使用Project-> References菜单,找到并选择Microsoft Speech Object Library。 InProc识别器需要额外的行,而共享识别器则不需要。对于InProc识别器,必须显式分配输入或输出的音频对象。

'Dim WithEvents RC As SpInProcRecoContext
Dim Recognizer As SpInprocRecognizer
Dim myGrammar As ISpeechRecoGrammar

Sub Form_Load()
    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

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

    Range("G8").Value = 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
Sub MyMacro()
    Call Form_Load
    Call RC_Recognition
End Sub````

Not able figure out how to call subroutine "RC_Recognition" that is taking some arguments.
excel vba sapi
1个回答
0
投票

Dim WithEvents RC As SpInProcRecoContext线是关键。这会自动将函数RC_Recognition映射为Recognition事件的处理程序。

© www.soinside.com 2019 - 2024. All rights reserved.