Speech Synthesis of New Mail in Microsoft Outlook
When new mail arrives in your Microsoft Outlook Inbox, the sender and subject
are read out aloud using the Microsoft text-to-speech control. Uses Microsoft
Agent.
The code consists of two sections. The first is a VBS script, which is placed
on the hard drive with a '.vbs' extension - in this example, as C:\SpeakNewMail.vbs
This self-contained script includes a function to speak a text string with
the Microsoft Agent control, and accepts the text string as a parameter in the
command-line.
Code Listing 1 - SpeakNewMail.vbs
Place this script on your hard drive as C:\SpeakNewMail.vbs
Option Explicit
Dim args, num
set args = WScript.Arguments
num = args.Count
if num = 0 then WScript.Quit
Dim text
text = ""
Dim k
for k = 0 to num - 1
text = text & " " & args.Item(k)
next
Speak(text)
FUNCTION Speak(txt)
Dim GenieRequest
Dim Genie
Dim Agent1
If ScriptEngineMajorVersion < 2 Then
EXIT FUNCTION
Else
Set Agent1 = WScript.CreateObject("Agent.Control.2", "AgentControl_")
Agent1.Characters.Load "Genie", "http://agent.microsoft.com/characters/v2/genie/genie.acf"
Set Genie = Agent1.Characters("Genie")
Genie.Get "State", "Showing"
Genie.MoveTo 100,100
Genie.Show
Wscript.Sleep 200
Genie.Speak (txt)
Wscript.Sleep (4000 + (200 * LEN(txt)) )
Genie.Hide
End If
END FUNCTION
Code Listing 2- ThisOutlookSession
The following code is placed in the ThisOutlookSession module of Microsoft
Outlook:
Private Sub Application_NewMail()
Dim oFolder
Dim oNewItem
Dim s
Set oFolder = GetNamespace("MAPI").GetDefaultFolder(6)
For Each oNewItem In oFolder.Items.Restrict("[Unread] = 0")
s = "Email from " & oNewItem.SenderName & ". Message - "
s = s & Trim(oNewItem.Subject)
Speak (Trim(s))
oNewItem.UnRead = 0
Next
End Sub
Public Function Speak(txt)
Dim spk As String
Dim t As String
t = " " & Trim(txt)
spk = "C:\SpeakNewMail.vbs"
spk = spk & " """ & t & """"
Call WSHRun(spk, 1, True)
End Function
Public Function WSHRun(strCmd As String, bVisible As Integer, bWait As Boolean)
'Shell run
Dim WSHShell
Set WSHShell = CreateObject("wscript.Shell")
WSHShell.Run strCmd, bVisible, bWait
Set WSHShell = Nothing
End Function
|