1

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!

3 Answers 3

1

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
::**********************************************
Sign up to request clarification or add additional context in comments.

Comments

1

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.

4 Comments

Using a temp file is the only way I can see, since batch doesn't provide API access. I'd create the file in %TEMP%, though, since write access to the current working directory (or the script directory) isn't always guaranteed.
@AnsgarWiechers - I assumed that if OP has rights to execute a script from a particular folder, he may also have rights to file manipulations as well. But I totally agree with your suggestion as it would not only hide the temp script, but is almost certain to be created in temp folder.
@PankajJaju Thanks! Working like a blast!
@AidenTooMLG - Happy to help. Don't forget to mark it as Accepted if this works for you.
0
@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".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.