Using Microsoft Speech Object Library in VB6
- June 27th, 2008
- Posted in VB 6
- Write comment
Here is a simple application in VB6 that uses Microsoft Speech Object Library, I’m bored so I’ve done some experiment and look what I’ve found. Actually, this is a part of our project in Major Elective 3, well.. umm I don’t know if this will help but anyways it’s my first step for writing my project and also for those who want to know the basic in how to use the library. So let’s begin.
First open a new project in VB and in the menu bar click Project -> References. Then in that list search for Microsoft Speech Object Library and check it, then click OK. [see image below]

Then in your form, create a TextBox control. Just drag and drop it to the form or double click the control. Then resize it, position it as you like. [see image below]

Let’s do the coding:
1 2 3 4 5 6 7 8 9 10 11 12 13 | Dim voice As New SpVoice Dim toSpeech() As String Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 32 Then toSpeech() = Split(Text1.Text, " ") voice.Speak (toSpeech(UBound(toSpeech))) ElseIf KeyAscii = 13 Then KeyAscii = 0 End If End Sub |
Here is a brief explanation of the code. First we declare voice as new SpVoice object and toSpeech() as a dynamic array String. As you can see the array has no size, so that we can size the array while the code is running.
Next, in the KeyPress event of our TextBox, The KeyAscii 32 is Space key value in your keyboard and if that value is equal to the KeyAscii, the Text1.Text will split each word with ” “(white space) delimiter. Then the voice.Speak will read the last item of the array toSpeech(). And if the KeyAscii value is equal to 13 which is Enter/Return Key, the keyAscii will set to 0 and the Enter/Return Key is disabled in your keyboard.
In other words, whenever the user hit Space Key the voice will read/speak the last word of the string in the Text1.txt. If the user hit Enter/Return Key, that key will disable.
That’s it, done. As for using the functionality of the library, I’m still experimenting.
Here is the file, if you want you can download it here.

Facebook
Linkedin
Virb
Flickr
Deviantart
Last FM
Delicious
Roboto
Tumblr
Twitter
Gtalk
Aim
Skype
Email

I just want the application in just reverse… I need to convert speech to text//.. I dont know what class and method to use… Ur work is good and useful too…