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 :
- Open the notepad in your system and start writing the below code.
Dim msg, sapi
msg=InputBox("Enter your text","Talk it")
- 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.
- First, we declare two variables using Dim (Data Input Method) as ‘msg’ and ‘sapi’
- ‘Msg’ is going to carry the message passed by the user though the Input box.
- We create a voice object named ‘sapi’ and going to use Speak function with it.
- 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 !! 🙂