How to make you computer talk, creating your own text-to-speech program !!

Hi geeks, Have you ever wondered how complex a text to speech program would be? Most of us might think that it’s a very complex process which might have several pages of code to complete!!

Today I’m going to show you a simple 4 line program to make your computer talk. This is going to be a simple program in when you need to enter text in the given text box and the computer reads it. But it isn’t that complex, we can’t even say complex it’s a very simple program.

This program is the basic concept which was used in windows narrator. This time I’m going to use VBscript instead of batch script to do this. Why?? Because it’s much simple process in VBscript.

You don’t need any compilers or IDKs to run this program, this is done using VBscript, so you just need a text editor (Notepad).

Even in my last post (on how to change windows password of other user) I didn’t use any IDKs since this is done in languages like batch script and VBscript, which are based on WSH (Window Scripting Host).It is a Microsoft scripting-friendly environment, which comes with most of the windows installation by default. You can know more about this from here.

Okay let’s start with a simple two-step process :

  1. Open the notepad in your system and start writing the below code.
    Dim msg, sapi
    msg=InputBox("Enter your text","Talk it")
    Set sapi=CreateObject("sapi.spvoice")
    sapi.Speak msg
  2. And now save it by pressing ctrl+S and select .vbs as file extension.

Are you going to just copy past the above code? Just type the whole code by yourself, trust me you will get some ideas while typing it.

And now GEEK section:

I’m not just going to say do this and do that and the magic happened. I’m just giving you an basic idea of building your own text-to-speech program. you can go on and customize, even i will be doing an article on using this program with some additional features to make your computer greet you on every startup. Now lets see what this code is going to do.

  1. First, we declare two variables using Dim (Data Input Method) as ‘msg’ and ‘sapi’
  2. ‘Msg’ is going to carry the message passed by the user though the Input box.
  3. We create a voice object named ‘sapi’ and going to use Speak function with it.
  4. We pass the ‘msg’ as the parameter to Speak function.

Note: This code must work fine in all windows PCs, if not make sure you have installed .Net framework in your PC. you can get it from here.

Soon I’ll be doing an article to show you geeks how we can change the voice that reads your text. So stay tuned !! happy coding !! 🙂 

Recommended -

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x