Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / VBScript
Article

Text-To-Speech

Rate me:
Please Sign up or sign in to vote.
4.32/5 (35 votes)
27 Nov 20012 min read 645.9K   9.9K   66   125
This is a tutorial which shows you how to create a simple program that will speak anything!

Introduction

This tutorial will show you how to create a very simple program that will actually speak! You will need to download the text-to-speech control if you have not already downloaded it.

Step 1 - Adding the controls

Firstly add a new Standard EXE project. Then change the projects name to TextToSpeech. Change the forms name to frmSpeak. Add the Direct Text-to-Speech control to the form by right clicking on the toolbox and then selecting components. Click on the Microsoft Direct Text-to-Speech item and then click OK.

Image 1

Draw the Text-to-speech control on the form and set its name property to spkSpeak and its visible property to false. Next add 10 buttons. Set their names to btnNumbers and their captions to one greater than their index. Then add a text box and change its name to txtText, its text property to nothing and its multiline property to true. Add a button below the text box. Set its name to btnSpeak and its caption to Speak.

Step 2 - Declaring the constants

The next step is to add the code. This code will say the caption of the button and then run a program depending on which button you clicked. Add this code to the general declarations:

Const Notepad = "c:\windows\notepad.exe"
Const Wordpad = "C:\program files\accessories\Wordpad.exe"
Const Paint = "c:\windows\Pbrush.exe"
Const Calculator = "c:\windows\Calc.exe"
Const Volume = "c:\windows\Sndvol32.exe"
Const InternetExplorer = "C:\Program Files\Internet Explorer\Iexplore.exe"
Const SoundRecorder = "c:\windows\Sndrec32.exe"
Const Clipboard = "c:\windows\Clipbrd.exe"
Const Dialer = "c:\windows\Dialer.exe"
Const Solitaire = "c:\windows\Sol.exe"

Step 3 - The code

Now add this code under the click event of btnNumbers:

spkSpeak.Speak "You clicked button number " & btnNumbers(Index).Caption & "."

Select Case Index + 1
  Case Is = 1
    Shell Notepad, vbNormalNoFocus
  Case Is = 2
    Shell Wordpad, vbNormalNoFocus
  Case Is = 3
    Shell Paint, vbNormalNoFocus
  Case Is = 4
    Shell Calculator, vbNormalNoFocus
  Case Is = 5
    Shell Volume, vbNormalNoFocus
  Case Is = 6
    Shell InternetExplorer, vbNormalNoFocus
  Case Is = 7
    Shell SoundRecorder, vbNormalNoFocus
  Case Is = 8
    Shell Clipboard, vbNormalNoFocus
  Case Is = 9
    Shell Dialer, vbNormalNoFocus
  Case Is = 10
    Shell Solitaire, vbNormalNoFocus
End Select

Then next piece of code will speak the text typed in the text box. Add this code to the btnSpeak click event:

spkSpeak.Speak txtText.Text

Image 2

This is how it works: when the button is clicked it says, "You clicked button number" and then it says the caption of the button. It then runs a program depending on which button you clicked. Also, when you type something in the text box, it reads the text and speaks it out. Your form should look something like this:

Image 3

If you run the program, it should speak the caption of the button you clicked and run a program and if you type something in the text box it should speak what you typed. Have fun!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRun LNK file from VB6 Pin
Hergass27-Oct-02 19:54
Hergass27-Oct-02 19:54 
GeneralRe: Run LNK file from VB6 Pin
Pete Bassett27-Oct-02 22:25
Pete Bassett27-Oct-02 22:25 
GeneralRe: Run LNK file from VB6 Pin
Hergass28-Oct-02 20:44
Hergass28-Oct-02 20:44 
GeneralRe: Run LNK file from VB6 Pin
Pete Bassett28-Oct-02 22:31
Pete Bassett28-Oct-02 22:31 
QuestionBare-Bones? Pin
Tc203729-Sep-02 20:41
Tc203729-Sep-02 20:41 
GeneralMore Voice Pin
sujeet2-Aug-02 18:17
sujeet2-Aug-02 18:17 
Generaltts engine Pin
ricardotapia24-Jul-02 7:45
ricardotapia24-Jul-02 7:45 
Generaltts engine Pin
Anonymous24-Jul-02 7:43
Anonymous24-Jul-02 7:43 
QuestionHow to make it work... Pin
Davy Mitchell20-Jul-02 7:10
Davy Mitchell20-Jul-02 7:10 
GeneralPropertys speech control Pin
Late Nighter14-Jul-02 20:04
sussLate Nighter14-Jul-02 20:04 
GeneralSounds like Yoda! Pin
Anonymous11-Jul-02 5:58
Anonymous11-Jul-02 5:58 
Generalspeech Pin
Anonymous10-Jul-02 0:29
Anonymous10-Jul-02 0:29 
GeneralRe: speech Pin
Manish Mishra14-Oct-03 23:03
Manish Mishra14-Oct-03 23:03 
Generaltext-speech vb code Pin
15-Jun-02 3:19
suss15-Jun-02 3:19 
GeneralRe: text-speech vb code Pin
BenjaminFM23-Dec-03 7:41
BenjaminFM23-Dec-03 7:41 
GeneralRe: text-speech vb code Pin
Anonymous21-Jan-04 8:33
Anonymous21-Jan-04 8:33 
GeneralVB Closed itself when i tried to run the program!!! Pin
27-Apr-02 20:48
suss27-Apr-02 20:48 
Generalsppech recognition Pin
14-Mar-02 19:06
suss14-Mar-02 19:06 
GeneralRe: sppech recognition Pin
23-Mar-02 5:04
suss23-Mar-02 5:04 
GeneralRe: sppech recognition Pin
Anonymous22-May-03 6:26
Anonymous22-May-03 6:26 
GeneralHELLO COMPUTER, SPEAK TO ME Pin
3-Dec-01 7:09
suss3-Dec-01 7:09 
GeneralUsing Voice Modem / Dialogic Pin
bhavin27-Nov-01 22:42
bhavin27-Nov-01 22:42 
GeneralDoesn't Work For Me Pin
Mark Jordan26-Nov-01 7:25
Mark Jordan26-Nov-01 7:25 
Generalspeech recognition Pin
Phil Sidari25-Nov-01 18:55
Phil Sidari25-Nov-01 18:55 
GeneralRe: speech recognition Pin
victorarokiaraj30-Jul-02 9:36
victorarokiaraj30-Jul-02 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.