Home Page - www.tele-pro.co.uk - Ecommerce Integration


Scripts > Text-to-Speech in MS Outlook

Microsoft Agent Genie DemoSpeech 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. Ensure the vbs file can perform TTS, by calling it directly like this:

wscript "C:\SpeakNewMail.vbs" "Hello World"

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/agent2/chars/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. Ensure that your security in MS Outlook is set to Medium to allow the macro to run.


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

 

This diagram shows where to place Code Listing 2:

The code is placed in the ThisOutlookSession module of Microsoft Outlook

 

See Also

 

Keywords

Script, program, free scripts, programming, Active Server Pages, ASP, VBScript, office development, text-to-speech, tts, ms agent, microsoft agent, automation, microsoft outlook

Your Feedback is Important

Why not let us know your feedback, or any suggestions you have? Your opinion and feedback is very important to us and to future website visitors, as it enables the continual improvement of products, services, scripts and software available from this website.

Anonymous

Discounts on thawte SSL Certificates - Official UK-based thawte referrer - SSL Hosting - Secure Image Hosting

Top | Home | ECommerce | Hosting | Site Map | Search | © 2003-6 | Contact