none
Late binding with Microsoft speech object library? RRS feed

  • Question

  • Hi all-

    I haven't messed with TTS from MS, but based on another recent post I tried some sample code and think that I could probably integrate this and get value from it almost immediately- if I can do so without my end users having to learn how to add the code reference to MS Speech Object Library.

    Can anyone provide syntax for late binding the speech library so I can have it work without any special user intervention, e.g. without a inherent reference in the VBE?

    For example, I get an error when trying the following with the reference unchecked:

    Set objSpeech = CreateObject("Speech.Object")

    I'm using Win7 x64 so I understand I'm limited to one voice, which is fine (some of my users are using x64, some are on x32, but I really only need one voice for any user so I can always use voice(0)

    Thanks!

    Tuesday, October 7, 2014 11:01 PM

Answers

  • This Late binding version worked for me:

    Public Function VoiceBox(ByVal prompt As String, _
        Optional ByVal buttons As VbMsgBoxStyle, _
        Optional ByVal title As String, _
        Optional ByVal helpFile As String, _
        Optional ByVal context As Long) As VbMsgBoxResult
         
         'For Early Bound object set a reference to Microsoft Speech Object Library:
         'C:\Windows\System32\Speech\Common\sapi.dll
         'Dim spv As SpeechLib.SpVoice
         'Set spv = New SpeechLib.SpVoice
         'Late Bound example follows:
        Dim spv As Object
        Set spv = CreateObject("SAPI.SpVoice")
        spv.Speak prompt, 1
        VoiceBox = MsgBox(prompt, buttons, title, helpFile, context)
        Set spv = Nothing
    End Function

    Source: Using Microsoft's Speech Object Library to Perform Text To Speech

    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Tuesday, October 7, 2014 11:36 PM

All replies

  • This Late binding version worked for me:

    Public Function VoiceBox(ByVal prompt As String, _
        Optional ByVal buttons As VbMsgBoxStyle, _
        Optional ByVal title As String, _
        Optional ByVal helpFile As String, _
        Optional ByVal context As Long) As VbMsgBoxResult
         
         'For Early Bound object set a reference to Microsoft Speech Object Library:
         'C:\Windows\System32\Speech\Common\sapi.dll
         'Dim spv As SpeechLib.SpVoice
         'Set spv = New SpeechLib.SpVoice
         'Late Bound example follows:
        Dim spv As Object
        Set spv = CreateObject("SAPI.SpVoice")
        spv.Speak prompt, 1
        VoiceBox = MsgBox(prompt, buttons, title, helpFile, context)
        Set spv = Nothing
    End Function

    Source: Using Microsoft's Speech Object Library to Perform Text To Speech

    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Tuesday, October 7, 2014 11:36 PM
  • Perfect, thank you!

    Thursday, October 9, 2014 7:11 PM