Reputation: 67
Here is the code:
Set sapi=Createobject("sapi.spvoice")
sapi.Speak ("Preparing your file now...")
I want to insert it into a batch file with other codes in it. It would be something like this;
Start google chrome
Open a new command prompt tab
Go to stack overflow
*Set sapi=Createobject("sapi.spvoice")
sapi.Speak ("Please subscribe to AstralWolf")*
How can I make that code VBS - Batch?
Thanks!
Upvotes: 1
Views: 3542
Reputation: 1
@echo off
cscript yourscript.vbs
Paste it into a batch, it will open it. To hide the VBS, right-click, properties, and check "Hidden". If you had it on, in Control Panel, untick "Show Hidden Icons".
Upvotes: 0
Reputation: 18827
You can try like that by the easy way when you call it as a function : Call:Speak "<your message goes here>"
@echo off
Start "" chrome.exe "www.stackoverflow.com"
Call:Speak "Please subscribe to AstralWolf"
exit /b
::**********************************************
:Speak <msg>
(
echo Set sapi=Createobject("sapi.spvoice"^)
echo sapi.Speak("%~1"^)
)>"%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs"
Del "%tmp%\%~n0.vbs"
exit /b
::**********************************************
Upvotes: 1
Reputation: 5471
A quick way to do it is to create a temp vbs file and run it from bat file. Sample batch file code would be something like the below
@echo off
cd %temp%
echo set varSAPI=WScript.CreateObject("sapi.spvoice") >> "tmp.vbs"
echo varSAPI.Speak "Please subscribe to AstralWolf" >> "tmp.vbs"
start tmp.vbs
pause
del tmp.vbs
@echo on
exit /b
Edit - As per @Ansgar Wiechers's suggestion, I am using temp folder.
Upvotes: 1