Introduction: Text to Speech Batch Program

As I promised earlier, I have made this instructable. This is part of a set of instructables I am making that focuses around one of the original features in my Mega_Menu V 2.4 batch program. I have one other, previously made instructable on my address book program which you can find here

This program has one major function only, making your computer "speak" whatever you write in the program. This is accomplished by creating a separate (temporary) VBs file that makes SAPI speak whatever you write. This file is deleted afterwards. 

Onto the code:

Note: I made a mistake, don't use underscores, use hyphens. I have corrected this.

Step 1:

@echo off
title Text to Speech Conversion
color 0a

rem The user decides what to convert here
:input
cls
echo What do you want the computer to convert into speech?
echo.
set /p text=

rem Making the temp file
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause
del temp%num%.vbs
goto input


If you do not want the screen to close for no reason, I suggest you follow the tip given and don't use spaces; use hyphens (-) instead.

Step 2:

That's it. I don't know why I added this last step, but all the cool-kids are doing it nowadays. Have fun?

P.S It said I needed more photos, so I gave Instructables a cheetah.

Comments

author
sijojijo (author)2017-03-13

which coding language is used here. please tell me how to use this code so that it may convert text to speech

author
SagarS102 (author)2017-01-18

Can we change the language.. I need Korean!!

author
mediageneric. (author)2015-08-28

Do something like:

set speech = Wscript.CreateObject("SAPI.spVoice")

speech.speak "Some--Text--Here"

set speech = Wscript.CreateObject("SAPI.spVoice")

speech.speak "Are--We--Clear"

And save as .vbs

Intead of adding the lines into .bat

call the .vbs from .bat

Note:Additional Information

Voice1 starts in sequence line while Voice2 and Text2 starts at the same time by adding the start command.

@echo off

Voice1

start Voice2

start Text1

I hope it Helps

author
vmars316 (author)mediageneric.2016-12-19

mediageneric. ,

I really don't know what is your reluctance to help me .

What I really, really, really, want to know is

given this *.vbs :

set speech = Wscript.CreateObject("SAPI.spVoice")

speech.speak "hello"

How can I get it to 'instead' , to read "hello" in from a *.txt file ?

I have Googled all over the internet , stackexchange , etc..

They are all 'how to read into a variable ' or something other than what I need .

Pls, What is the syntax for input into the 'speech.speak' command ? :

speech.speak C:\hello.txt

If you don't know , please say so .

Then I'll look else where .

Thanks

author
vmars316 (author)2016-12-15

Hi mediageneric. ,

How can I get your tts script to accept input from a .txt file ?

Thanks

author
vmars316 (author)2016-12-05

Hello & Thanks ,

Pls , how can I get code to speak a *.txt file ?

Thanks

author
bcoleman43 (author)2015-11-06

Can I add additional text that will open a file on my computer when you run this script? For instance the script says welcome to chr kiosk and then open the program file....

author
Nikhilk12 (author)2015-08-13

how to create delay For Ex: if we enter "23 45" and it is speaking without some gap to here clearly
how to make it delay for word to word

author
Monacraft (author)2013-09-06

Awesome PP, just changed your code so that it takes multiple lines of input. Best thing is since the "SAPI.spVoice" pauses just after it finishes, at the end of each line there is a slight pause.

@echo off
title Text to Speech Conversion
color 0a

rem The user decides what to convert here
:start
cls
echo What do you want the computer to convert into speech?
echo.

rem Making the temp file
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"

rem Taking Input
:input
set text=
set /p text=
if not "%text%"=="" (
echo speech.speak "%text%" >> "temp%num%.vbs"
goto :input
)

start temp%num%.vbs
Pause Echo Speaking . . .
del temp%num%.vbs
goto start


Just wondering do you know of any other auto-voicing programs installed by default in a windows computor?

author
Monacraft (author)Monacraft2013-09-06

Found error: 3rd Last line -
Pause |Echo Speaking . . .

author
SirG1 (author)Monacraft2015-01-05

Remove "|Echo Speaking . . ."

I think that will work

author
Prof. Pickle (author)Monacraft2013-09-11

Thanks for your help, and no. There are no pre-installed auto-voicing programs on Windows that I know of, but I'm sure there's some free or open-source programs for download.

author
K-hoorps (author)2014-12-14

This is so funny to play around with.

author
POPK (author)2014-11-25

I'm trying to add this to a batch file that acts sorta like a siri for desktop, and when i put it in this script it tells me: Can not find script file "C:\Users\...\Desktop\temp20004.vbs" What does this mean.

*Please note that this script did work by itself in its own program.

author
Prof. Pickle (author)POPK2014-11-25

Depends on how you're calling on it through the batch file. I find the best way is to use either Wscript of Cscript within batch files. The only difference between them is that Wscript makes it's own output windows and Cscript outputs it directly to the batch window.

So, where you're calling on the script, either use

cscript //Nologo "C:\Users\...\Desktop\temp20004.vbs"

or

wscript //Nologo "C:\Users\...\Desktop\temp20004.vbs"

author
DavidL10 (author)2014-09-30

thanks for this. I added voice welcoming to my program.

http://www.mediafire.com/download/1uey3fmglej5a96/Davids_Hacking_System_-_Version_0.1.6.exe

author
mnutsch (author)2014-02-24

I love this! Thank you!

author
Shadman93 (author)2013-11-22

Awesome...great work......Actually I m expert in java programming as well as ASP.NET/C#
but batch file programming is going out of my box.......
Perfect.....really impressive.........ur logical reasoning n knowledge...both are perfect..

author
AdnanAd (author)2013-11-06

This was really nice one, Can I set the different voice samples using this script

author
Prof. Pickle (author)AdnanAd2013-11-06

The language and accent that it speaks in is on your end of the bargain. To access what voices you can change it to, go to Control Panel/Speech Recognition/ and on the left it should say "text to speech". There it should open a properties box where you can change the voice, speed and other details. To download more voices, see here.

author
Prof. Pickle (author)2013-06-15

In the line echo speech.speak "%text%" >> "temp%num%.vbs" replace "%text%" with what you want it to say.

author
el-xavi26 (author)2013-02-19

WOW dude this is beast... you should do a tutorial!

author
Prof. Pickle (author)el-xavi262013-02-19

Thank you, and a tutorial of how I did it or what each line does?

author
el-xavi26 (author)Prof. Pickle2013-04-23

Hoe you did it!

author
Prof. Pickle (author)el-xavi262013-04-24

Might add it to the back of this one soon.

author
neo coder (author)2013-02-01

what is the batch command for reading from a text file called "weather.txt" and it is in c:/scripts/weather" so the path is "c:/scripts/weather/weather.txt"?

author
Prof. Pickle (author)neo coder2013-02-01

There is no specific command for narrating anything with batch, but you can make one. Luckily for you, someone has thought about your predicament and made an instructable about how to make a VBscript narrate a file's contents. Because I don't know exactly how it works (VBs isn't my forte), I'll leave it to you to do your own research. Here's a link to the instructable by SCRIPTmaster.

If I knew how the script worked, I could help you out a lot more. Sorry.

author
jabarilondon13 (author)2012-12-15

cool batch

author

i use space bar and it works fine for me lol

author

Yeah, I added something into the code that stops it, but I forgot to take out the warning.

author
Prof. Pickle (author)2012-11-19

Next instructable will be about a batch program to open, explore and browse your folders. It'll be out within the week.

About This Instructable

28,931views

16favorites

License:

Bio: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope ... More »
More by Prof. Pickle:How to Create your own Commands with BatchStart a batch file completely hiddenTips on how to find errors in code (focused on DOS)
Add instructable to: