Making your computer talk with VBScript.

Who doesn’t enjoy making their computer talk? Here are some fun scripts to turn your computer into a chatterbox.

This first one tells the time.

' speaktime.vbs
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak "The time is " & Hour(Now) & " " & Minute(Now)

A variation of this script is one that vaguely tells you the time. I got the inspiration for this script from a program called FuzzyClock that does the same thing, albeit quietly.

' fuzzyclock.vbs
Dim strHour, strMin, FuzzHour, FuzzMin, NextHour
FuzzTime = Now
StrHour = Hour(FuzzTime)
StrMin = Minute(FuzzTime)

if StrMin = 0 then
FuzzMin = "exactly "
elseif StrMin > 0 and StrMin < 5 then
FuzzMin = "just after "
elseif StrMin >= 5 and StrMin < 10 then
FuzzMin = "well past five after "
elseif StrMin >= 10 and StrMin < 15 then
FuzzMin = "nearly a quarter after "
elseif StrMin = 15 then
FuzzMin = "a quarter after "
elseif StrMin >= 15 and StrMin < 20 then
FuzzMin = "just past a quarter after "
elseif StrMin >= 20 and StrMin < 25 then
FuzzMin = "well past a quarter after "
elseif StrMin >= 25 and StrMin < 30 then
FuzzMin = "nearly half past "
elseif StrMin = 30 then
FuzzMin = "half past "
elseif StrMin >= 30 and StrMin < 35 then
FuzzMin = "just half past "
elseif StrMin >= 35 and StrMin < 40 then
FuzzMin = "well gone half past "
elseif StrMin >= 40 and StrMin < 45 then
FuzzMin = "nearly a quarter to "
StrHour = 1 + StrHour
elseif StrMin = 45 then
FuzzMin = "a quarter to "
StrHour = 1 + StrHour
elseif StrMin >= 45 and StrMin < 50 then
FuzzMin = "past a quarter to "
StrHour = 1 + StrHour
elseif StrMin >= 50 and StrMin < 55 then
FuzzMin = "well past a quarter to "
StrHour = 1 + StrHour
elseif StrMin >= 55 then
FuzzMin = "almost "
StrHour = 1 + StrHour
end if

if strHour = 13 or strHour = 01 then 
FuzzHour = "one"
elseif strHour = 2 or strHour = 14 then 
FuzzHour = "two"
elseif strHour = 3 or strHour = 15 then 
FuzzHour = "three"
elseif strHour = 4 or strHour = 16 then
FuzzHour = "four"
elseif strHour = 5 or strHour = 17 then 
FuzzHour = "five"
elseif strHour = 6 or strHour = 18 then
FuzzHour = "six"
elseif strHour = 7 or strHour = 19 then 
FuzzHour = "seven"
elseif strHour = 8 or strHour = 20 then
FuzzHour = "eight"
elseif strHour = 9 or strHour = 21 then 
FuzzHour = "nine"
elseif strHour = 10 or strHour = 22 then
FuzzHour = "ten"
elseif strHour = 11 or strHour = 23 then
FuzzHour = "eleven"
elseif strHour = 12 or strHour = 00 then 
FuzzHour = "twelve"
end if


wscript.echo  "It's " & FuzzMin & FuzzHour & "."

This next one tells you the day of the week, along with some added commentary.

' speakweek.vbs
Set objVoice = CreateObject("SAPI.SpVoice")

dtmToday = Date()

dtmDayOfWeek = DatePart("w", dtmToday)

Select Case dtmDayOfWeek
    Case 1 objVoice.Speak "Working on a SUNDAY? Something's not right here."
    Case 2 objVoice.Speak "Today's Monday. Blargh."
    Case 3 objVoice.Speak "Today's Tuesday. Leave me alone."
    Case 4 objVoice.Speak "It's Wednesday. At least the week's half over."
    Case 5 objVoice.Speak "Today's Thursday. The week's almost over."
    Case 6 objVoice.Speak "It's FRIDAY! WOOT!"
    Case 7 objVoice.Speak "What are you doing here on Saturday? Take the day off!"
End Select

Finally, here’s a script that prompts you for some text you want your computer to recite.

' speaker.vbs
strText = InputBox("What do you want me to say?", _
    "Speaker")
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak strText

Have much fun.

Advertisements

Tags:

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: