Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text to Speech (Vb 6)

    Hi!
    I 'm trying to add Text to Speech support to a Vb program, and I get a compile error:
    "Function or interface marked as restricted, or function uses a variable type not supported by Visual Basic".
    I have referenced Microsoft Speech Object Library in my project.
    Speech works in my computers' control panel and in Excel.
    Any help shall be very appreciated.

    Here is an example code:
    Public Sub HelloWorld()
    Dim obj As SpeechLib.SpVoice
    Set obj = New SpVoice
    obj.speak "Hello World" 'Causes a Compile Error!!!
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Text to Speech (Vb 6)

    What is the speak method? The fact that it didn't capitalize itself is rather suspicious.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Text to Speech (Vb 6)

    I copied your code into the on click event of a command button on a VB6 form, and added a reference to Microsoft Speech Object Library. The code ran without a hitch. Have you tried the code in a new VB6 application? If it works there, there must be some kind of interference with something else in the application where you get the compile error.

  4. #4
    New Lounger
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text to Speech (Vb 6)

    Thanks for your reply.
    I tried to paste the code in a new application as you described, and I got the same error.
    I tried in vba (in a few versions of office) and I got the same error.
    I suppose I shall have to get hold of a different computer to try.
    Note that the Object Browser shows the following definition for spVoice.Speak
    Sub Speak(pwcs As String, dwFlags As <Unsupported variant type>, pulStreamNumber As <Unsupported variant type>)
    Member of SpeechLib.SpVoice
    The fact that Vb considers the parameters 'Unsupported variant types' is probably the source of the problem, but the question is why is a DOUBLE WORD unsupported.
    I wonder if perhaps by you the Object Browser displays it differently.
    Thanks and regards
    Moses

  5. #5
    New Lounger
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text to Speech (Vb 6)

    The Speak method tells the Voice to speak, as it's name implies.

    Add a reference to the Microsoft Speech Object Library and the method shall be available in the Object Browser.

    Thanks & regards,
    Moses

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text to Speech (Vb 6)

    Works here too.

    Frightening voice though !!

    Could it be that the library isn't registered correctly ?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Text to Speech (Vb 6)

    Apparently, you have a different version of the Speech library. On my system, the definition of SPVoice.Speak is

    Function Speak(Text As String, [Flags As SpeechVoiceSpeakFlags = SVSFDefault]) As Long
    Member of SpeechLib.SpVoice

    The MS Speech Library file is C:Program FilesCommon FilesMicrosoft SharedSpeechsapi.dll, dated August 4, 2004; it came with Windows XP SP2.

    I suspect that you will need to reinstall the Speech library, but I'm afraid I don't know how to do that.

  8. #8
    New Lounger
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text to Speech (Vb 6)

    Hans and Dave, You saved my day!

    You were correct that I had a different version of sapi.dll.
    I've been using Windows 98 (b/c of compatibility problems), and it's version of sapi.dll is slightly older and apparently incompatible with Vb.

    The solution I found was to first uninstall sapi.dll by running
    regsvr32.exe /u "C:Program FilesCommon FilesMicrosoft SharedSpeechsapi.dll".
    I then copied the speech files from Windows XP, replacing the Win98 files.
    I then registered the new sapi.dll by running
    regsvr32.exe "C:Program FilesCommon FilesMicrosoft SharedSpeechsapi.dll".
    Hey presto, it worked!

    The definition of the function in Object Browser is now as you described it.

    Does this mean that I have to include the current sapi.dll file in the installation package of my program, for all Win98 users?

    Sincere thanks,
    Moses

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Text to Speech (Vb 6)

    > Does this mean that I have to include the current sapi.dll file in the installation package of my program, for all Win98 users?

    Yes, I think so - chances are that most Windows 98 users will have the older version of sapi.dll.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text to Speech (Vb 6)

    I wish you'd never posted this.
    I wish I'd never read Woody's latest 'Zine.
    I wish I didn't have my computers audio output linked to every stereo amplifier and loudspeaker in my home.
    It was bad enough having Rowan Atkinson announce "If I'd wanted to speak with a vegetable, I'd have bought one at the market" with the arrival of each new mail.
    Once I have worked out how to switch voices within a VBA function, I'll probably d/l extra voices, and then my life will be truly miserable.
    Especially if I use different voices for different Paragraph Styles or for different formats within a spreadsheet (male for text, female for numeric, ...)

    (grin!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •