Text to Speech Batch Program

33,699

16

37

Posted

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.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Microcontroller Contest

      Microcontroller Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    34 Comments

    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?

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

    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.

    Remove "|Echo Speaking . . ."

    I think that will work

    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

    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