或是裝完speechsdk51.exe之后可以參考 C:/Program Files/Microsoft Speech SDK 5.1/Samples/Scripts/SimpleTTS/SimpleTTS.html這個文件。 如果讓電腦聽你的命令,下邊是vbs代碼 復制代碼 代碼如下: '========================================================================== ' Name : CommandPC.VBS ' AUTHOR : HUAYING ' DATE : 2005-1-31 '========================================================================== Dim CommandDictionary '命令字典對象 Dim WshShell 'WshShell對象提供對本地Windows程序的訪問。 Dim ScriptComplete '程序結束標志 Dim SR '語音識別(Speech Recognition)對象 Dim Grammar '語音識別的命令語法對象 '初始化命令字典對象,可根據自己的需要添加命令 Set CommandDictionary = CreateObject("Scripting.Dictionary") CommandDictionary.Add "上網","""C:/Program Files/Internet Explorer/iexplore.exe""" '注意雙引號的數目 CommandDictionary.Add "計算器", "calc" CommandDictionary.Add "記事本", "notepad" CommandDictionary.Add "空當接龍", "freecell" Set WshShell = CreateObject("WScript.Shell") '創建WshShell對象 ScriptComplete = False '初始化程序結束標志 '創建語音識別對象,調用由"Command.XML"所定義的語法,并啟動語音識別引擎 Set SR = WScript.CreateObject("SAPI.SpSharedRecoContext", "RecoContext_") Set Grammar = SR.CreateGrammar Grammar.CmdLoadFromFile "x.xml", SLODynamic Grammar.CmdSetRuleIdState 0, 1 MsgBox "你好,主人,請吩咐。" '等候你的語音命令(需要安裝麥克風) '當識別出"命令結束"命令時程序結束 Do WScript.Sleep 1000 Loop Until ScriptComplete MsgBox "歡迎再跟我說話,再見!" '你的語音命令被識別 Sub RecoContext_Recognition(ByVal StreamNumber,ByVal StreamPosition,ByVal RecognitionType,ByVal Result ) Text = Result.PhraseInfo.GetText '獲取語音識別引擎所識別的命令 If Text "命令結束" Then WshShell.Run CommandDictionary.Item(Text) '由WshShell對象Run方法執行你的命令 Else ScriptComplete = true '程序結束標志 End If End Sub
================================== x.xml源碼 復制代碼 代碼如下: ?xml version="1.0" encoding="gb2312" ? GRAMMAR LANGID="804" RULE NAME="命令" TOPLEVEL="ACTIVE" L P 上網 /P P 計算器 /P P 記事本 /P P 空當接龍 /P P 命令結束 /P /L /RULE /GRAMMAR