Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get your Script to Speak 1

Status
Not open for further replies.

BillDoor

IS-IT--Management
Jun 28, 2004
112
GB
Hi

Sorry if you already know this. I found it last week and haven't been able to stop playing with it yet.

I know it works on Windows XP, I haven't had a chance to try it on other versions of Windows.

Code:
'Create Object
Set objVoice = CreateObject("SAPI.SpVoice")

Const SVSFlagsAsync = 1
Const SSFMCreateForWrite = 3


'Basic speech
objVoice.Speak "Hello I am talking to you"

'Speech while continuing with the rest of the script.
'(warning, if the script finished before the speech, the speech will stop)
objVoice.Speak "You should see a message box, while I am talking", SVSFlagsAsync
MsgBox "This is the message box that I mentioned."


'List voices that are installed.
For Each strVoice in objVoice.GetVoices
    Wscript.Echo strVoice.GetDescription
Next


'Change voice (these may not work if you don't have these voices installed).
Set objVoice.Voice = objVoice.GetVoices("Name=Microsoft Anna").Item(0)
objVoice.Speak "Hi, this is Microsoft Anna."

Set objVoice.Voice = objVoice.GetVoices("Name=Microsoft Sam").Item(0)
objVoice.Speak "And this is Microsoft Sam"


'Record speech to a WAV file
Set objFile = CreateObject("SAPI.SpFileStream.1")
objFile.Open "C:\Record.wav", SSFMCreateForWrite
Set objVoice.AudioOutputStream = objFile
objVoice.Speak "This text will be recorded to be played back later"

There are a few examples in there that show some of what can be done. You can download other voices from the MS website:


The Microsoft Anna voice sounds really great and comes with Vista and some other MS Applications (possibly Office 2003 and/or AutoRoute/MapPoint 2006.
 
Are there voices installed by default?

[monkey][snake] <.
 
On Windows XP there is Microsoft SAM, which sounds a bit like Stephen Hawking, there are other voices available for free from the MS website.

If you check in Control Panel there should be a speech icon (unless speech has been disabled or removed) this will show you which voices you have installed and allow you to select the default voice to use.

Microsoft Anna, which is a new voice, sounds almost human and comes with Windows Vista as standard, but it can be added to Windows XP by installing AutoRoute 2006, it could be called MapPoint or Streets & Trips in the US. I don't know if it is available to download on it's own.
 
That's pretty cool.

[monkey][snake] <.
 
That's known since Feb'05:
thread329-1004531
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top