Text to Speech Batch Program
Intro: 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.
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.
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.
P.S It said I needed more photos, so I gave Instructables a cheetah.
37 Comments
birdbath09 1 year ago
I put if %text% == exit goto 1
so if you type exit it will take you to :1
But for some reason this made it so if you type multiple words (like "hey there") It crashes. But if you type one word (like "hey") it works fine. Do you know what's going on?
balligowri70 2 years ago
zero-0000 5 years ago
Monacraft 10 years ago
@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?
Monacraft 10 years ago
Pause |Echo Speaking . . .
Prof. Pickle 10 years ago
lepinekong 6 years ago
You can try this one: easy to install by just copying one line in Powershell see demo tour https://www.youtube.com/watch?v=u3rIyxtpEFY
SirG1 9 years ago
Remove "|Echo Speaking . . ."
I think that will work
BinT1 6 years ago
I am currently working on a tiny bot and want to add ur TTS code..i did that and its not working ..can u tell me what i did wrong?..im new to this..!
this is my code:
-------------------------------------------------------------------------------------------------------
@echo off
mode 1000
if not exist data.txt echo.>data.txt
echo HI!..I am BabyBot.I am a tiny AI bot.Please teach me how to interact with humans!
echo.
Echo.
echo Press any key if you are interested in helping me!
pause > nul
:getName
ECHO.
Echo.
echo WHAT IS YOUR NAME?
set "name="
SET /P NAME=
if not defined NAME goto getName
ECHO HI, %NAME% !
set /p text= HI
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 >nul
del temp%num%.vbs
pause
:begin
set /p text="Ask me something %name% : "
for /f "tokens=1,* delims=@" %%i in (data.txt) do (
if /i "%text%"=="%%i" (
echo *** %%j
goto begin
)
)
echo --- I don't know that.
set /p answer=--- What would be a good answer to '%text%'?
echo %text%@%answer%>>data.txt
echo --- thank you
goto begin
---------------------------------------------------------------------------------------------------
thank you for all the tutorials btw
BinT1 6 years ago
i need help
sijojijo 7 years ago
which coding language is used here. please tell me how to use this code so that it may convert text to speech
SagarS102 7 years ago
mediageneric. 8 years ago
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
vmars316 7 years ago
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
vmars316 7 years ago
Hi mediageneric. ,
How can I get your tts script to accept input from a .txt file ?
Thanks
vmars316 7 years ago
Hello & Thanks ,
Pls , how can I get code to speak a *.txt file ?
Thanks
bcoleman43 8 years ago
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....
Nikhilk12 8 years ago
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
K-hoorps 9 years ago
This is so funny to play around with.
POPK 9 years ago
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.