批处理之家's Archiver

CrLf 发表于 2014-11-7 18:07

vbs 语音识别

基本来自网上,但网上版本太多,也不知道哪个是原创的
有所精简和改进[code]Const SLODynamic = 0

Dim CommandDictionary '命令字典对象
Dim WshShell   'WshShell对象提供对本地Windows程序的访问。
Dim SR   '语音识别(Speech Recognition)对象
Dim Grammar '语音识别的命令语法对象

'初始化命令字典对象,可根据自己的需要添加命令而来
Set CommandDictionary = CreateObject("Scripting.Dictionary")
CommandDictionary.Add "计算器",   "calc"
CommandDictionary.Add "记事本",   "notepad"
CommandDictionary.Add "测试", "notepad ceshi.vbs"
CommandDictionary.Add "打开键盘", "osk"

Set WshShell = CreateObject("WScript.Shell") '创建WshShell对象

'创建语音识别对象,调用由"Command.XML"所定义的语法,并启动语音识别引擎
Set SR = WScript.CreateObject("SAPI.SpSharedRecoContext", "RecoContext_")
Set Grammar = SR.CreateGrammar
Grammar.Reset
Grammar.CmdLoadFromFile "COMMAND.XML", SLODynamic
Grammar.CmdSetRuleIdState 0, 1

Set objTTS = CreateObject( "SAPI.SpVoice" )

MsgBox "语音识别系统测试"
WScript.Sleep 100000000

'你的语音命令被识别
Sub RecoContext_Recognition(ByVal StreamNumber, ByVal StreamPosition, ByVal RecognitionType, ByVal Result )
        Text = Result.PhraseInfo.GetText     '获取语音识别引擎所识别的命令
       
        WScript.Sleep 1000
       
        Set fso=CreateObject("scripting.filesystemobject").opentextfile("记录.log",2)
        fso.write Text  & vbCrLf & "Text"
       
        If CommandDictionary.Exists(Text) Then
                objTTS.Speak "正在打开" & Text
                WshShell.Run CommandDictionary.Item(Text)
        End If
       
        If Text = "命令结束" Then
                objTTS.Speak "命令结束,再见!"
                WScript.Sleep 2000
                Set objTTS = Nothing
                WScript.Quit
        End If
End Sub[/code]COMMAND.XML 的内容如下:[code]<?xml version="1.0" encoding="gb2312" ?><GRAMMAR LANGID="804"><RULE NAME="命令" TOPLEVEL="ACTIVE"><L>

<P>计算器</P>
<P>记事本</P>
<P>打开键盘</P>
<P>命令结束</P>

</L></RULE></GRAMMAR>[/code]

CrLf 发表于 2014-11-7 18:09

微软 TTS 的识别率还是不够,而且会受内置的命令干扰,所以不是很实用
国内语音方面做得比较好的还属科大讯飞,杠杠的

9zhmke 发表于 2014-11-20 09:18

[quote]微软 TTS 的识别率还是不够,而且会受内置的命令干扰,所以不是很实用
国内语音方面做得比较好的还属科大讯 ...
[size=2][color=#999999]CrLf 发表于 2014-11-7 18:09[/color] [url=http://www.bathome.net/redirect.php?goto=findpost&pid=157201&ptid=32842][img]http://www.bathome.net/images/common/back.gif[/img][/url][/size][/quote]


    有没办法调用讯飞的呢?

CrLf 发表于 2014-11-20 14:39

没研究过,不知道,回头试下
手机上用得多,电脑的语音输入略显鸡肋

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.