If your machine is installed with office, you may not need to install the following software. Because my machine is installed with openoffice, I installed it in advance.
Speechsdk51.exe
CNSpeechPackage. msi
The two software. If you want your computer to read aloud, refer to the following code:
Copy codeThe Code is as follows: ReadAllTextFile = CreateObject ("Scripting. FileSystemObject"). OpenTextFile (Wscript. Arguments (0), 1). ReadAll
Function RegExpTest (patrn, strng)
Dim regEx, Match, Matches 'to create a variable.
Set regEx = New RegExp 'to create a regular expression.
RegEx. Pattern = patrn 'setting mode.
RegEx. IgnoreCase = true' is used to set Case sensitivity.
RegEx. Global = true' to set full availability.
Set Matches = regEx. Execute (strng) 'to Execute the search.
For Each Match in Matches 'traverses the Matches set.
RetStr = RetStr & Match. value &""
RetStr = RetStr & vbCRLF
Next
RegExpTest = RetStr
End Function
Set objVoice = CreateObject ("SAPI. SpVoice ")
Set objVoice. Voice = objVoice. GetVoices ("Name = Microsoft Simplified Chinese"). Item (0)
ObjVoice. Rate = 3' speed:-10, 10 0
ObjVoice. Volume = 100 'sound: 0,100 100
ObjVoice. Speak RegExpTest ("[\ u4e00-\ u9fa5]", ReadAllTextFile)
Or after installing speechsdk51.exe, you can refer
C: \ Program Files \ Microsoft Speech SDK 5.1 \ Samples \ Scripts \ SimpleTTS \ SimpleTTS.html.
If you want your computer to listen to your command, the following is the vbs codeCopy codeThe Code is as follows: '================================================ ==========================================
'Name: CommandPC. VBS
'Author: HUAYING
'Date: 2005-1-31
'================================================ ==========================================
Dim CommandDictionary 'command dictionary object
The Dim WshShell 'wshshell object provides access to the local Windows program.
Dim ScriptComplete 'program end sign
Dim SR 'speech Recognition (Speech Recognition) object
Dim Grammar 'COMMAND syntax object for Speech Recognition
'Initialize the command dictionary object. You can add commands as needed.
Set CommandDictionary = CreateObject ("Scripting. Dictionary ")
CommandDictionary. Add "Surfing", "" C: \ Program Files \ Internet Explorer \ ipolice.exe "" 'pay attention to the number of double quotation marks
CommandDictionary. Add "Calculator", "calc"
CommandDictionary. Add "notepad", "notepad"
CommandDictionary. Add "cool", "freecell"
Set WshShell = CreateObject ("WScript. Shell") 'to create a WshShell object
ScriptComplete = false' end flag of the initialization program
'Create a Speech Recognition object, call the syntax defined by "Command. XML", and start the speech recognition engine.
Set SR = WScript. CreateObject ("SAPI. SpSharedRecoContext", "RecoContext _")
Set Grammar = SR. CreateGrammar
Grammar. javasloadfromfile "x. xml", SLODynamic
Grammar. CmdSetRuleIdState 0, 1
MsgBox "Hello, Master. Please give me your order. "
'Wait for your voice command (microphone installation required)
'Program ended when the "command ended" command is identified
Do
WScript. Sleep 1000
Loop Until ScriptComplete
MsgBox "Welcome to talk to me again. Goodbye! "
'Your voice command is recognized
Sub RecoContext_Recognition (ByVal StreamNumber, ByVal StreamPosition, ByVal RecognitionType, ByVal Result)
Text = Result. PhraseInfo. gettext' get the Command recognized by the speech recognition engine
If Text <> "command end" Then
WshShell. Run CommandDictionary. Item (Text) 'is Run by the Run method of the WshShell object.
Else
ScriptComplete = true' end flag
End If
End Sub
========================================
X. xml source codeCopy codeThe Code is as follows: <? Xml version = "1.0" encoding = "gb2312"?>
<Grammar langid = "804">
<Rule name = "command" TOPLEVEL = "ACTIVE">
<L>
<P> surfing the Internet </P>
<P> calculator </P>
<P> notepad </P>
<P> air-cooled solitaire </P>
<P> command end </P>
</L>
</RULE>
</GRAMMAR>
======== Run the vbs directly on a Chinese machine. The 0x800000052 error may occur. solution:
Control Panel --- speech-Speech Recognition tab ------------ changed to Microsoft Simplified Chinese