Speaking Script

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Speaking Script

Post by kpassaur » Thu Sep 25, 2008 10:23 am

I have found an Autohotkey script that I would like convert to use in MS and need a little help. It is a standard vbscript script inside and only a couple of lines. I have looked at the script for Merlin on the forum and have played with that, but it requires SAPI 4 and and the TTS speach engine which Microsoft has decided not to support. This uses SAPI 5 and it looks quite simple


TXT := "Something I want to say"

Speak:
TEMPFILE = %TEMP%\TALK.vbs
IfExist, %TEMPFILE%
FileDelete, %TEMPFILE%
FileAppend, Dim Talk`nSet Talk = WScript.CreateObject("SAPI.SpVoice")`nTalk.Speak "%TXT%", %TEMPFILE%
RunWait, %TEMPFILE%
FileDelete, %TEMPFILE%
Return

I just don't know how to covert it to MS so I can compile it.

Any help would be appriecated

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Sep 25, 2008 2:02 pm

Temp files just to run VBScript? Try this:

Code: Select all

VBSTART
Sub Speak(text)
 Dim Talk
 Set Talk = CreateObject("SAPI.SpVoice")
 Talk.Speak text
End Sub
VBEND

VBRun>Speak,Hello Keith
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Fun with MS - Joke Reader

Post by kpassaur » Thu Sep 25, 2008 3:45 pm

Frist off,

Thanks Marcus,

I though I would contribute a working script (haven't done much of that in a while) so I used the speaking part that you helped me with.

This script will go out to Comedy Central's website using MS's HTTPRequest to randomly grab a page with a joke on it. At that point it will parse the text until only the joke is captured. The joke will be displayed in a window where it can be read or listened to.
It can be addictive



VBSTART
Sub Speak(text)
Dim Talk
Set Talk = CreateObject("SAPI.SpVoice")
Talk.Speak text
End Sub
VBEND

Let>JText=

Dialog>Dialog1
Caption=Read Text
Width=445
Height=250
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=1
Resize=0
Memo=msMemo1,16,16,401,153,%JText%
Button=Get a Joke,16,184,75,25,1
Button=Listen to Text,90,184,75,25,3
Button=Exit,165,184,75,25,2
EndDialog>Dialog1

Show>Dialog1
Label>mainloop
GetDialogAction>Dialog1,dresult
IF>dresult=1,getjoke
IF>dresult=2,EOF
IF>dresult=3,Speakit
Wait>.1
Goto>mainloop

SRT>Speakit
VBRun>Speak,%Dialog1.msMemo1%
ResetDialogAction>Dialog1
End>Speakit


SRT>getjoke
Label>Runagain
Random>12000,rnumber
//Let>rnumber=1%DiceResult1%
Let>file=
DeleteFile>%TEMP_DIR%\test.txt
Let>HTTP_TIMEOUT=10
HTTPRequest>http://jokes.comedycentral.com/random_j ... MLResponse
IF>HTMLResponse=404 Error connecting to host
MDL>Unable to get a Joke - Will try again in 10 minutes
Wait>6000
Goto>Runagain
Else
WriteLn>%TEMP_DIR%\test.txt,result,HTMLResponse


Endif
Let>k=1

Label>start

ReadLn>%TEMP_DIR%\test.txt,k,line


If>line=##EOF##,finish
Position>,line,1,StartPos
If>StartPos>0

Let>z=k+1
Label>startreadjoke
ReadLn>%TEMP_DIR%\test.txt,z,line

If>line=##EOF##,finish

Position>,line,1,StartPos
If>StartPos>0,finish

Let>file=%file%%line%%CRLF%
Let>z=z+1
Goto>startreadjoke
Goto>finish
Endif
Let>k=k+1
Goto>start

Label>finish
If>%file%=
Goto>Runagain
Endif
StringReplace>file, ,,file
StringReplace>file,,%CRLF%,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,,,file
//StringReplace>file,. ,.%CRLF%,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file, ,,file
StringReplace>file,",",file
StringReplace>file,,",file
StringReplace>file,,",file
StringReplace>file,Â,",file
StringReplace>file,?,%CRLF%,file
StringReplace>file,!,%CRLF%,file
StringReplace>file,“,,file
StringReplace>file,”,,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,,,file
StringReplace>file,Ã,,file
StringReplace>file,¢,,file
StringReplace>file,â,,file
StringReplace>file,¢,,file
StringReplace>file,",,file

DeleteFile>%TEMP_DIR%\joke.txt
WriteLn>%TEMP_DIR%\joke.txt,result,%file%
Readfile>%TEMP_DIR%\joke.txt,sayit
Let>Dialog1.msMemo1=%sayit%
ResetDialogAction>Dialog1
End>getjoke

Label>EOF
Exit>0

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Fri Sep 26, 2008 9:18 pm

Nice Work. This is fun and very cool.

Ed

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Apr 20, 2012 5:10 pm

mtettmar wrote:Temp files just to run VBScript? Try this:

Code: Select all

VBSTART
Sub Speak(text)
 Dim Talk
 Set Talk = CreateObject("SAPI.SpVoice")
 Talk.Speak text
End Sub
VBEND

VBRun>Speak,Hello Keith
I get the following error when I run Marcus' example.
Microsoft VBScript runtime error: 429

ActiveX Component can't create object: 'SAPI.SpVoice'

Line 4, column 1
I've searched for several hours and installed several programs including Microsoft's Speech API but no luck.

OS Name: Microsoft Windows7
Version: 6.1.7600 Service Pack 3 Build 7600

Any help or suggestions are appreciated.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts