Intelligent machines capable of speech are often the stuff of futuristic sci-fi movies, but you can turn any computer into a chatty Cathy. Even though we aren’t yet at the stage with computers where they can interact with us like people, there are a few tools and simple scripts we can write to make any computer that is running Windows speak to us.
A Little (Visual) Basic History
In 1988, the first iteration of VBScript or (Visual Basic Scripting Edition) appeared and was still a very primitive version of what we have today. Over the years, the need for an easy to use and lightweight scripting language for Microsoft increased. Because of this, the company kept working on it and finally released it to the public in 1996.It is a simple script that uses COM (Component Object Model) to create, read, update, and delete files within Microsoft operating systems. Since Windows 98 was released, it has been installed with every computer. It is highly versatile because of the fact that the VBScript host environment can be embedded within programs using Microsoft Script Control. It is used quire often with Internet Information Services, Windows Script Host, and Internet Explorer.
But, that’s enough of the technical jibber jabber. Let’s get down to it and learn how to make your computer talk!
Single Use VBScripts
Creating a visual basic script is very easy and doesn’t require any special programs. Though there are programs you can use to write more highly advanced scripts, most programmers and people who dabble in writing scripts just use Microsoft’s Notepad.Let’s start the process by opening Notepad. After you have opened Notepad all you need to do is type in the following code or simply copy and paste it into the notepad window. In order to change what your script makes the computer say, simply replace the section that says “The geeks shall inherit the earth” with whatever you want to hear.
dim speechobject set speechobject=createobject("sapi.spvoice") speechobject.speak "The geeks shall inherit the earth"
After you have successfully entered the text you wish to hear, just press “File,” and click on the “Save As…” option.
Find a place where you want to save the image. For this example, I am saving it to an empty folder in the Downloads directory. The important thing you need to do is give it a name that ends with .vbs. This will tell the computer that you are not saving a plain text file; rather, you are saving a VBScript. We will name this sample “Geek test.vbs” as shown below.
Now you can go ahead and close the notepad and navigate to the folder where you saved the VBScript. You will notice that the icon is not the normal TXT icon. It is a small blue scroll on a white backdrop. Double click on this icon to launch your single use script and listen to your text. Congratulations, you’ve just created your first script.
Now, to get the hang of it, try to create a few more scripts with any text you want to hear. Alternatively, you can right click on the VBScript and select the “Open with…” option then choose notepad to edit the text within the same file.
Text to Speech Script
Now that you know how to write a single use script and have probably played with it a few times, you may be getting a bit bored. That’s why we are going to kick it up a notch.The next thing we will learn is how to create a script that is slightly more advanced than the single use script. This will create a dialog box that you can type text into and have it read back to you by your PC.
Start by opening up your notepad again and entering this script or copy and pasting it into the notepad window.
Dim message, sapi message=InputBox("What shall I say, your Geekness?","I speak for you.") Set sapi=CreateObject("sapi.spvoice") sapi.Speak message
After the code has been entered, simply save the file as “Text to Speech.vbs” as shown earlier to finalize the script. Once it has been saved, navigate to the location where it is, and double click on it. You will notice that window is called “I speak for you.” and the prompt to enter text to be vocalized is “What shall I say, your Geekiness?” You can always alter these to say anything you want.
For now, let us enter “The geeks shall inherit the earth” then press the “OK” button to run the script and hear your text out loud.
Greetings VBScript Script
This is getting pretty fun, but your computer still isn’t interacting with you very much. Now we will try another simple script that takes into account the time of day as well as the appropriate response for the time of day. This script will read your computer’s time and, based on that, it will greet you in a certain way.Start by opening your notepad and inserting this short script. You can replace the section that has the greetings of the day with any phrase you want to hear as well as replace Geekmeister with your own name.
Set Sapi = Wscript.CreateObject("SAPI.SpVoice") dim str if hour(time) < 12 then Sapi.speak "Good Morning Geekmeister " else if hour(time) > 12 then if hour(time) > 16 then Sapi.speak "Good evening Geekmeister " else Sapi.speak "Good afternoon Geekmeister " end if end if end if
Now you can save the text document as a VBS file. Once you have done that, go to the folder where it is saved and double click on it. Based on the time that your computer shows, it will either say “Good morning, good afternoon or good evening Geekmeister.”
The script tells it that if the clock reads anything before 12, it is morning, and that anything after 12 is afternoon; however, it also has a clause that says even if it is after 12, as long as the time is past 16:00 (4 pm) it becomes evening.
Time of Day VBScript Script
If you would like to get a little bit more advanced and receive the time, you can create a new notepad and enter this script.The script may look complicated, but it is essentially telling your computer what to say and how to say it based on the time that is shown on your computer’s clock. You can always replace the “The current time is” with any introduction for the time that you want.
Set Sapi = Wscript.CreateObject("SAPI.SpVoice") Sapi.speak "The current time is"if hour(time) > 12 then Sapi.speak hour(time)-12 else if hour(time) = 0 then Sapi.speak "12" else Sapi.speak hour(time) end if end ifif minute(time) < 10 then Sapi.speak "o" if minute(time) < 1 then Sapi.speak "clock" else Sapi.speak minute(time) end if else Sapi.speak minute(time) end ifif hour(time) > 12 then Sapi.speak "P.M." else if hour(time) = 0 then if minute(time) = 0 then Sapi.speak "Midnight" else Sapi.speak "A.M." end if else if hour(time) = 12 then if minute(time) = 0 then Sapi.speak "Noon" else Sapi.speak "P.M." end if else Sapi.speak "A.M." end if end if end if
Now you just need to save the file as a VBScript as you did in the previous steps and then navigate to that folder. If everything went well, you should be able to double click on it and hear the computer tell you the time.
Startup Greeting
Now that you know how to make your computer greet you and tell you the time, how cool would it be if the computer would do that when you turn on the computer. It is actually very easy to do if you just combine the two scripts and put them in the right place.Start by opening up Microsoft notepad and copying this code into the window. It is simply a copy of both codes combined for you. Remember that you can change the greeting to “What’s up dude, Hello Master, Greetings your almighty highness,” or anything you want your computer to say to you.
Once you have copied this entire code exactly as it is, into notepad, go ahead and save it as “Startup greeting.vbs”. It can also be called anything you want, but for the purposes of this demonstration, it is easier if we’re all on the same page. Now that it has been saved, you can double click on the VBScript file to hear it greet you and tell you the time.Set Sapi = Wscript.CreateObject("SAPI.SpVoice") dim str if hour(time) < 12 then Sapi.speak "Good Morning Geekmeister " else if hour(time) > 12 then if hour(time) > 16 then Sapi.speak "Good evening Geekmeister " else Sapi.speak "Good afternoon Geekmeister " end if end if end if Sapi.speak "The current time is"if hour(time) > 12 then Sapi.speak hour(time)-12 else if hour(time) = 0 then Sapi.speak "12" else Sapi.speak hour(time) end if end ifif minute(time) < 10 then Sapi.speak "o" if minute(time) < 1 then Sapi.speak "clock" else Sapi.speak minute(time) end if else Sapi.speak minute(time) end ifif hour(time) > 12 then Sapi.speak "P.M." else if hour(time) = 0 then if minute(time) = 0 then Sapi.speak "Midnight" else Sapi.speak "A.M." end if else if hour(time) = 12 then if minute(time) = 0 then Sapi.speak "Noon" else Sapi.speak "P.M." end if else Sapi.speak "A.M." end if end if end if
If you want it to play when you turn on your computer, like Jarvis from Iron Man, simply select the file and drag it with your mouse down to the “Start button.” Without releasing your mouse move it onto “All Programs” then find the “Startup” folder and release your mouse button.
If, for some reason this does not work for you, you can also manually navigate to the startup folder. You will first go to the folder where your “Startup greeting.vbs” is saved and copy it.
The next step is to type the following path into the top of any Explorer window and press “Enter”. You will just need to change USERNAME with the name you use for your computer account.
C:\Users\USERNAME\AppData\Roaming\Microsoft\Once you are in the startup folder, just paste the vbs file and you are good to go. Now, the next time you start your computer and log in, it should automatically greet you and inform you of what time it is.
Windows\Start Menu\Programs\Startup
0 comments:
Post a Comment