Link to home
Start Free TrialLog in
Avatar of J-Antonio
J-AntonioFlag for United States of America

asked on

Need help with Outlook 2010 VB Script for Speaking Reminders

Hello Experts,

A very kind and knowledgeable Expert wrote a VBA Script for me which speaks the Reminders in Outlook 2010 (originally it was in 2007) when they pop up.  

It works great, except that I sometimes get an error when it first runs.  A copy of a screen capture of the error is attached to this message.

Also, for some reason, even though my name, Antonio, is before the script subroutine (I think), it speaks it at _every_ reminder, "Antonio do this", "Antonio remember that".  I would just like it to speak my name when the reminder window pops up, then announce/speak all of the Reminder Subjects.  

Furthermore, I understand from researching this that there are ways to alter the voice, and the speed of the speech.  If this is not too difficult, I would like to know how to do this as well.

Thank you for your kind consideration of my issue.  I am grateful for any input.  I am learning VBA, but it is slow going, and I want to learn to make this work as soon as I can.

A copy of the VB script is also attached, if I can figure out the correct way to do that _and_ attach the error image.  If not, I will post it in a reply to this post.

Best regards,

~Antonio
Private Sub Application_Reminder(ByVal Item As Object)
 
Dim synth As SpVoice ' Create the speech Object
Set synth = New SpVoice ' Set it to a new SP voice Class

synth.Speak "Antonio"

Select Case Item.Class
     Case olAppointment '26
        synth.Speak Item.Subject, SVSFlagsAsync + SVSFPurgeBeforeSpeak
      Case olMail '43
        synth.Speak Item.Subject, SVSFlagsAsync + SVSFPurgeBeforeSpeak
      Case olTask '48
        synth.Speak Item.Subject, SVSFlagsAsync + SVSFPurgeBeforeSpeak
End Select
Do
    DoEvents
Loop Until synth.WaitUntilDone(10)
 
Set synth = Nothing
 
End Sub

Open in new window

VB-Script-Error-Message-Capture.png
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Application_Reminder is run once per reminder that is due hence it is called in it's entirity each time.  It will be difficult to change this and be seamless though in theory a task could be triggered for one minute hence that does the speech with the reminders updating a global string that is used by the timed task.

Chris
Avatar of J-Antonio

ASKER

Thanks Chris,
I kind of realized this just a day or so ago.  That, even if they are separate Reminder Subjects, each Reminder is treated as a different "event" by Outlook, so that means there is no real way for it to distinguish, unless, as you said, there was an update to the global string.  So, it runs the script on each reminder event.
I have also had the code re-written, as attached, so that there are no errors, and I have the speech slowed down to where I would like.  If I could only change the speaking voice...  Is there an easy way to do that with this script?
Take good care,
~Antonio

Private Sub Application_Reminder(ByVal Item As Object)

    On Error GoTo errHdr

    Dim synth As Object
    Set synth = CreateObject("SAPI.SpVoice")
    
    If synth Is Nothing Then
        MsgBox "[Error]=" & " can not create voice object ."
        GoTo exitHere
    End If

    synth.Rate = -1      'speak speed'
    synth.Volume = 100  'speak volume

    synth.Speak "Antonio"
    
    Select Case Item.Class
        Case 26, 43, 48
            synth.Speak Item.Subject, 3
    End Select

    Do
        DoEvents
    Loop Until synth.WaitUntilDone(10)
     
    Set synth = Nothing

If False Then
errHdr:
        MsgBox "[Error]=" & Err.Description, vbInformation + vbOKOnly
End If

exitHere:
End Sub

Open in new window

Assuming you have multiple voices then:

    synth .getvoices.item (0)

Will be the default and 1 ... number will be the additional voices.

Chris
Hello Chris!
I tried adding that, using the number 2 instead of 1, and got the error message seen in the attached image.  
Is there any easy way to allow Outlook access to the speaking voices that are part of the Windows 7 OS?
I await your thoughtful reply.
Best regards,
~Antonio

Capture.PNG
The fact that 0 works and perhaps 1 implies that the mechanism is the same in win 7 but that the extra voices are not registered to sapi.  At this point I don't know but i'll try and look around to see if I can get any clues.

Chris
That's alright, if it is not on the "tip of your tongue", don't worry about it.  I don't want you to spend your time on something so trivial...  I just thought it was easy.
Thanks, though!
~Antonio
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the try.  I appreciate that.  I guess it wasn't meant to be...  Take good care,  ~Antonio