Jackey's 感悟

Do Research

Monthly Archives: 十月 2011

转载Making PC’s Speak with SAPI.SpVoice

From Evernote:

[转载]Making PC’s Speak with SAPI.SpVoice

Clipped from: http://www.visualbasicscript.com/Making-PC39s-Speak-with-SAPISpVoice-m63061.aspx

Not a useful script, but a little fun never the less.

this is a few examples of usage for the SAPI.SpVoice Object (microsoft sam)

How to Make Your PC talk. (Talk Box Basic)

'* X BiLe
'* Local Talk Box
'* Solo VBS


'create the voice object
Set VObj = CreateObject("SAPI.SpVoice")

'get what the user wants to say, exit if cancel or return no msg
MSG = InputBox("Type what you want the PC to say" & VBCRLF & VBCRLF & VBCRLF & "To End enter Nothing or push the Cancel button", "Voice Box By X BiLe", "")
If MSG = "" Then WScript.quit: Else

'use the VObj to speak msg
with VObj
.Volume = 100
.Speak MSG
end with


Now the question is further posed on how to actually get someone elses pc to talk using remote access.

this challenge can easily be tackled assuming you have C$ access (C Share)

Please also note that this is not the only way to do this like all things in computers, please remember that in all scripts you do

'* X BiLe
'* Remote Voice Send
'* Solo VBS

'get ip
IP = InputBox("Type the Name or IP of the PC to send Voice to:", "Remote Voice Send By X BiLe", "")
If IP = "" Then WScript.quit: Else

'get MSG
MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")
If MSG = "" Then WScript.quit: Else

'vbs command to send
A = "on error resume next" & VBCRLF & _
" CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _
" CreateObject(""Scripting.FileSystemObject"").DeleteFile (""C:Voice1.vbs"")"

' Create the vbs on remote C$
CreateObject("Scripting.FileSystemObject").OpenTextFile("\" & ip & "C$Voice1.vbs",2,True).Write A

' Run the VBS through Wscript on remote machine via WMI Object Win32_Process
B = GetObject("winmgmts:\" & IP & "rootcimv2:Win32_Process").Create("C:windowssystem32wscript.exe ""C:Voice1.vbs""", null, null, intProcessID)

like all objects to be created in VBS there are more than just the 3 properties i actually use here.

SAPI.SpVoice Properties:

‘.Pause = pause speaking
‘.resume = resume after pause
‘.Rate = speed at which voice speaks
‘.Voice = you can use set and a voice value to change the voice (if multiple exist on machine)
‘.Volume = volume of voice (not system volume, just voice)
‘.WaitUntilDone = wait until done – dont know how else to say that 😉

how to set the 3 useful voice Properties

 'create object and then setup the properties
Set VObj = CreateObject("SAPI.SpVoice")
with VObj
Set .voice = .getvoices.item(0)
.Volume = 100
.Rate = 3
end with

Please notice that the ‘.getvoices.item(0)’ has refrenced item 0, the getvoices is in an array (if multiple are present)

to retrive the names of the values you could do a simple call like:

 'create object and then loop for the index and name
Set VObj = CreateObject("SAPI.SpVoice")
For Each Voice In VObj.getvoices
I = I + 1
msgbox "" & (I - 1) & " - " & Voice.GetDescription

i dont know, its just one of those toy codes any ways