VBS calls Chinese speech let your computer listen to your command implementation code _vbs

Source: Internet
Author: User
Tags sapi
If you have the machine itself installed Office, you may not need to install the following software, my machine because it is OpenOffice, so I installed in advance
Speechsdk51.exe
Cnspeechpackage.msi
The two software. If you want your computer to read aloud, refer to the following code
Copy Code code as follows:

Readalltextfile=createobject ("Scripting.FileSystemObject"). OpenTextFile (wscript.arguments (0), 1). ReadAll
Function regexptest (PATRN, STRNG)
Dim regEx, Match, matches ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether case sensitive.
Regex.global = True ' Sets full availability.
Set matches = Regex.execute (strng) ' performs a search.
For the Match in matches ' traverses the matches collection.

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 ' Voice: 0,100 100
Objvoice.speak regexptest ("[\u4e00-\u9fa5]", Readalltextfile)

or after loading Speechsdk51.exe, you can refer to
C:\Program Files\Microsoft Speech SDK 5.1\samples\scripts\simpletts\simpletts.html this file.
If you let the computer listen to your command, the following is the VBS code
Copy Code code 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 flag
Dim SR ' speech recognition (Speech recognition) object
Dim Grammar ' speech recognition Command syntax object
' Initialize the command Dictionary object to add commands to your needs
Set commanddictionary = CreateObject ("Scripting.Dictionary")
Commanddictionary.add "Internet", "" "" "C:\Program files\internet Explorer\iexplore.exe" "" ' notice the number of double quotes
Commanddictionary.add "Calculator", "Calc"
Commanddictionary.add "Notebook", "notepad"
Commanddictionary.add "Gap Solitaire", "FreeCell"
Set WshShell = CreateObject ("Wscript.Shell") ' Create WshShell Object
Scriptcomplete = False ' Initialize the end of the program flag
' Create speech recognition objects, invoke the syntax defined by ' Command.xml ', and start the speech recognition engine
Set SR = WScript.CreateObject ("SAPI.") Spsharedrecocontext "," Recocontext_ ")
Set grammar = SR. Creategrammar
Grammar.cmdloadfromfile "X.xml", slodynamic
Grammar.cmdsetruleidstate 0, 1
MsgBox "Hello, master, give me your orders." "
' Wait for your voice command (you need to install a microphone)
' When the command end command is recognized, the program ends
Todo
Wscript.Sleep 1000
Loop Until Scriptcomplete
MsgBox "Welcome to talk to me again, goodbye!" "
' Your voice commands are recognized.
Sub recocontext_recognition (ByVal streamnumber,byval streamposition,byval recognitiontype,byval result)
Text = Result.PhraseInfo.GetText ' gets the command recognized by the speech recognition engine
If Text <> "command End" Then
Wshshell.run Commanddictionary.item (Text) ' Execute your command by the WshShell object Run method
Else
Scriptcomplete = True ' End of program flag
End If
End Sub

==================================
X.xml Source
Copy Code code as follows:

<?xml version= "1.0" encoding= "gb2312"?>
<grammar langid= "804" >
<rule name= "command" toplevel= "ACTIVE" >
<L>
<P> Internet </P>
<P> Calculator </P>
<P> Notepad </P>
<P> Solitaire </P>
<P> Command End </P>
</L>
</RULE>
</GRAMMAR>

======== is running this VBS directly on Chinese machines, there is a good chance of 0x80045052 errors and solutions:
Control Panel---Voice-Speech recognition tab------------changed to Microsoft Simplified Chinese
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.