Text to Speech Batch Program

Published

Introduction: Text to Speech Batch Program

About: 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 to become a programmer, although in what category is still a mystery (...

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.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    34 Discussions

    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?

    4 replies

    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.

    0
    user
    BinT1

    9 months 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

    0
    user
    BinT1

    9 months ago

    i need help

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

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

    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

    1 reply

    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

    Hi mediageneric. ,

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

    Thanks

    Hello & Thanks ,

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

    Thanks

    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....

    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

    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.

    1 reply

    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"

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

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