| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2318 人关注过本帖
标题:哪位大神帮我把这段语音转文字的VBS代码翻成VFP的,谢谢!
只看楼主 加入收藏
jlliushi
Rank: 2
等 级:论坛游民
帖 子:33
专家分:10
注 册:2021-12-24
结帖率:100%
收藏
已结贴  问题点数:30 回复次数:14 
哪位大神帮我把这段语音转文字的VBS代码翻成VFP的,谢谢!
下面是VBS代码的语音识别程序,哪位大神帮我把这段代码翻成VFP的,谢谢!
'VBS语音识别程序
Dim ScriptComplete '程序结束标志
Dim SR '语音识别(Speech Recognition)对象
Dim Grammar '语音识别的命令语法对象
'初始化命令字典对象,可根据自己的需要添加命令
Set WshShell = CreateObject("WScript.Shell") '创建WshShell对象
ScriptComplete = False '初始化程序结束标志
'创建语音识别对象,调用由"Command.XML"所定义的语法,并启动语音识别引擎
Set SR = WScript.CreateObject("SAPI.SpSharedRecoContext", "RecoContext_")
Set Grammar = SR.CreateGrammar
Grammar.CmdLoadFromFile "Command.xml", 0
Grammar.CmdSetRuleIdState 0, 1
'等候你的语音命令(需要安装麦克风),当识别出"命令结束"命令时程序结束
Do
   WScript.Sleep 1000
Loop Until ScriptComplete
'语音命令被识别
Sub RecoContext_Recognition(ByVal StreamNumber,ByVal StreamPosition,ByVal RecognitionType,ByVal Result )
    Text = Result.PhraseInfo.GetText '获取语音识别引擎所识别的命令
    If Text <> "命令结束" Then
       MsgBox Text
     Else
       ScriptComplete = true '程序结束标志
    End If  
End Sub
搜索更多相关主题的帖子: 对象 语音识别 结束 语音 命令 
2021-12-28 07:25
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
只看明这几句
SR = CreateObject("SAPI.SpSharedRecoContext", "RecoContext_")
Grammar = SR.CreateGrammar
Grammar.CmdLoadFromFile("Command.xml", 0)
Grammar.CmdSetRuleIdState(0, 1)
INKEY(1)
其他的不清楚做什么、用在哪
2021-12-28 09:40
jlliushi
Rank: 2
等 级:论坛游民
帖 子:33
专家分:10
注 册:2021-12-24
收藏
得分:0 
回复 2楼 吹水佬
inkey(1)是等待1秒,让用户键盘输入。
而本任务要等待的是:
SAPI中的ISpeechRecoContext(事件)
Recognition事件:当SR引擎产生一个识别时发生;
它被作为语音识别中最重要的一个事件,因为它返回一次成功识别的结果。一次成功的识别就是一个单词或者短语满足识别上下文的的开发语法的要求或者语音质量满足最低信任值。如果上述两点都不符合,引擎将会返回FalseRecognition事件。被发音的内容不满足信任值有很多原因,如背景干扰、不清晰语音、不常用单词或短语。
结果成员中包括识别结果对象,并且从这些可以得出更多关于语音的信息。

不知道这个事件在VFP中怎么写...


[此贴子已经被作者于2021-12-28 09:58编辑过]

2021-12-28 09:49
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
回复 3楼 jlliushi
没玩过语音的东西,电脑也没有咪头。
既然是COM的东西,应该可以封装成VFP的类,重载属性、方法和事件
2021-12-28 09:56
jlliushi
Rank: 2
等 级:论坛游民
帖 子:33
专家分:10
注 册:2021-12-24
收藏
得分:0 
回复 4楼 吹水佬
这个博客里有4篇介绍SAPI的博文,可惜我看不太懂,您看能不能把那个事件移植到VFP里写。。。
https://

就是不知道这个事件在VFP里怎么写
Sub RecoContext_Recognition(ByVal StreamNumber,ByVal StreamPosition,ByVal RecognitionType,ByVal Result )     '如果语音命令被识别时发生
    。。。。
End Sub

[此贴子已经被作者于2021-12-28 10:11编辑过]

2021-12-28 10:07
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
回复 5楼 jlliushi
看了一下 sapi.dll
SpSharedRecoContext的事件接口大概意思一下,没有声音设备测试不了,有些事件入口参数数据类型还没测试确定。
程序代码:
sr = CreateObject("SAPI.SpSharedRecoContext")
srEvent = CREATEOBJECT("srEvents")
EVENTHANDLER(sr, srEvent)
Grammar = sr.CreateGrammar
**Grammar.CmdLoadFromFile("Command.xml", 0)
**Grammar.CmdSetRuleIdState(0, 1)
INKEY(1)
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

2021-12-28 19:39
cjc1010
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:65
专家分:195
注 册:2006-4-16
收藏
得分:0 
按我的理解:Recognition事件是控件RecoContext固有的。VB的Sub RecoContext_Recognition(ByVal Result)表示按件RecoContext的Recognition事件里给参数Result赋值。对应的在VFP里,如果要用text1显示Result的值,应该是在控件RecoContext的Recognition事件里写:
LPARAMETERS Result
thisform.text1.value=thisform.RecoContext.Result.PhraseInfo.GetText。试试?

[此贴子已经被作者于2021-12-29 16:44编辑过]

2021-12-29 16:43
jlliushi
Rank: 2
等 级:论坛游民
帖 子:33
专家分:10
注 册:2021-12-24
收藏
得分:0 
回复 6楼 吹水佬
出错信息:方法程序或事件不能含有嵌套的过程或类定义。
2021-12-30 09:05
jlliushi
Rank: 2
等 级:论坛游民
帖 子:33
专家分:10
注 册:2021-12-24
收藏
得分:0 
回复 7楼 cjc1010
RecoContext不是个控件,是VFP用Set RecoContext = WScript.CreateObject("SAPI.SpSharedRecoContext", "RecoContext_")创建的一个对象;
Recognition是创建的这个对象本身的事件:当Recognition产生一个语音识别时发生,它是语音识别中最重要的一个事件,因为它返回一个成功识别的结果;
现在的问题是,不知道这个事件在VFP中怎么写...
2021-12-30 09:13
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
以下是引用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
2021-12-30 10:23
快速回复:哪位大神帮我把这段语音转文字的VBS代码翻成VFP的,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034252 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved