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.
37 Comments
Question 10 months ago
So underneath the set /p text=
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?
Question 1 year ago on Step 1
can you please explain this programme
4 years ago
how can i add the whisper function to this?
9 years ago on Introduction
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?
Reply 9 years ago on Introduction
Found error: 3rd Last line -
Pause |Echo Speaking . . .
Reply 9 years ago on Introduction
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.
Reply 4 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
Reply 8 years ago on Introduction
Remove "|Echo Speaking . . ."
I think that will work
5 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
5 years ago
i need help
6 years ago
which coding language is used here. please tell me how to use this code so that it may convert text to speech
6 years ago
Can we change the language.. I need Korean!!
7 years ago on Introduction
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
Reply 6 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
6 years ago
Hi mediageneric. ,
How can I get your tts script to accept input from a .txt file ?
Thanks
6 years ago
Hello & Thanks ,
Pls , how can I get code to speak a *.txt file ?
Thanks
7 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....
7 years ago on Introduction
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
8 years ago on Introduction
This is so funny to play around with.
8 years ago on Introduction
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.