Search Tools Links Login

Using the Windows Speech Synthesizer

Visual Basic 6, or VB Classic

This article explains how to use the windows speech synthesizer, which can be useful sometimes, such as in programs that have an Impaired person help option. Note: to use this, you have to have a speech synthesizer installed, but usually XP has one automatically.

Original Author: Miles Cloud


This is only the basics, because I figured out how to use it today, but it still does what it is supposed to.
First of all, open a new project, Doesn't matter what kind, and click Project|Referances, and look for "Microsoft Speech Object Library". Check the box by it, and click OK. This is to basically connect the DLL to you're project. Once you did, Open the code window, and go to the Declarations section. In it, type:
Public Voice As New SpVoice
Public VoiceStatus As New ISpeechVoiceStatus
Now, whenever you want Windows voice synthesizer to say something, use a line of code like this:
Voice.Speak "This is an example of how to use Microsofts Voice Synthesizer"
You can replace the text in the parenthesis with ANYTHING, including variables and other various information. Only one problem: It freezes the program until it's done speaking. This can be a major problem. How is it fixed? By adding a flag, called SVSFlagsAsync. This will allow the program to operate while it's speaking. So now, it's like this:
Voice.Speak "This is an example of how to use Microsofts Voice Synthesizer", SVSFlagsAsync
To Make it state the contents of a variable, you'd say something like this:
Voice.Speak LabelDescription.Caption, SVSFlagsAsync
Voice.Speak MyVariable, SVSFlagsAsync
Pretty simple eh?
That's all I could figure out so far, but I'll keep experimenting, and see what I can do. This might also work on older versions of VB, but I'm not sure, so even if you don't have Visual Basic 5 or 6, try it and tell us if it works. ^_^

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 118 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.