Sunday, March 02, 2008

Voice Messages in VBA

Speech in VBA or Spell out messages and instructions in VBA

If you are developing applications for one and all, it would be great if you broadcast the messages in voice format. Here is the way you can achieve it in Excel VBA 2007

Sub Speak_Out()

Application.Speech.Speak "Speaking out to you..."

' Synchronous Method
For i = 1 To 100
i = i + 1
Next i

Application.Speech.Speak "Synchronous Speak"

Application.Speech.Speak "asynchronous Speak - the following code will be executed, when this statment is executed", True

MsgBox "Wait..."

For i = 1 To 100
i = i + 1
Next i

End Sub


The synchronous message allows the message to be executed and holds subsequent code processing. In asynchronous Speak the code after the Speak statements are executed while the message is spelt out.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi there,
    I couldn't figure out what sync/async was and how to specify it. Searching, I found this, but wasn't sure what you are saying, so I had to try some of this to figure it out. Perhaps you could re-word some of this to make it clearer.

    Below is the Sub I used to better see it in action it.

    Where you have this "...the following code will be executed, when this statment is executed", you mean _while_ the speech is executed"

    When you say this:

    "In asynchronous Speak the code after the Speak statements are executed while the message is spelt out."
    "spelt out" implies the individual *letters* are spoken.

    It would also help your demo if you:
    1 - Add a MessageBox before the first loop so it can be seen to appear after the speech.
    2 - Make the two spoken texts similar.

    Asynchronous:
    Subsequent code executes *while* the speech is being spoken.

    Synchronous:
    Subsequent code is not executed until the speech finishes.

    VBA formats are thus:

    Application.Speech.Speak "Text to speek", [True/False]
    Application.Speech.Speak ("Text to speek"), [True/False]

    Where False is the default.

    Regards, Steve N.
    My Demo:
    ---------------------------------------------
    Sub Speak_Out()

    Application.Speech.Speak "Synchronous Speak – Speech must finish before more code executes.
    ' False is the Default.

    MsgBox "This will execute AFTER the speech has finished."

    Application.Speech.Speak "Asynchronous Speak - the following code will be executed, while the speech is ongoing", True

    MsgBox "This executed while the speech is on-going"

    End Sub
    ----------------------------------

    ReplyDelete
  3. Anonymous1:14 PM

    Very helpful post and follow-up comments.
    This info made the issue quite clear.
    And the Sub Speak_Out() works great! Thank-you!

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.