以下是引用jlliushi在2021-12-30 09:05:03的发言:
出错信息:方法程序或事件不能含有嵌套的过程或类定义。
我这运行下面代码只提示音频设备设置问题(可能是没有音频设备),没见其他异常,也没见触发了哪个事件。
用EVENTHANDLER绑定事件的做法在某些COM控件是有效的,但对SAPI的东西没试过,不知有无效。
程序代码:
sr = CreateObject("SAPI.SpSharedRecoContext")
srEvent = CREATEOBJECT("srEvents")
EVENTHANDLER(sr, srEvent)
Grammar = sr.CreateGrammar
RETURN
DEFINE CLASS srEvents AS session OLEPUBLIC
IMPLEMENTS _ISpeechRecoContextEvents IN "SAPI.SpSharedRecoContext"
PROCEDURE _ISpeechRecoContextEvents_Adaptation(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 1
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_AudioLevel(StreamNumber as NUMBER, StreamPosition as VARIANT, AudioLevel as NUMBER) as VOID
? 2
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_Bookmark(StreamNumber as NUMBER, StreamPosition as VARIANT, BookmarkId as VARIANT, Options as NUMBER) as VOID
? 3
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_EndStream(StreamNumber as NUMBER, StreamPosition as VARIANT, StreamReleased as LOGICAL) as VOID
? 4
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_EnginePrivate(StreamNumber as NUMBER, StreamPosition as VARIANT, EngineData as VARIANT) as VOID
? 5
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_FalseRecognition(StreamNumber as NUMBER, StreamPosition as VARIANT, Result as OBJECT) as VOID
? 6
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_Hypothesis(StreamNumber as NUMBER, StreamPosition as VARIANT, Result as OBJECT) as VOID
? 7
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_Interference(StreamNumber as NUMBER, StreamPosition as VARIANT, Interference as OBJECT) as VOID
? 8
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_PhraseStart(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 9
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_PropertyNumberChange(StreamNumber as NUMBER, StreamPosition as VARIANT, PropertyName as STRING, NewNumberValue as NUMBER) as VOID
? 10
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_PropertyStringChange(StreamNumber as NUMBER, StreamPosition as VARIANT, PropertyName as STRING, NewStringValue as STRING) as VOID
? 11
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_Recognition(StreamNumber as NUMBER, StreamPosition as VARIANT, RecognitionType as NUMBER, Result as OBJECT) as VOID
? 12
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_RecognitionForOtherContext(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 13
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_RecognizerStateChange(StreamNumber as NUMBER, StreamPosition as VARIANT, NewState as NUMBER) as VOID
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_RequestUI(StreamNumber as NUMBER, StreamPosition as VARIANT, UIType as STRING) as VOID
? 14
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_SoundEnd(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 15
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_SoundEnd(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 16
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_SoundStart(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 17
ENDPROC
PROCEDURE _ISpeechRecoContextEvents_StartStream(StreamNumber as NUMBER, StreamPosition as VARIANT) as VOID
? 18
ENDPROC
ENDDEFINE