Click here to Skip to main content
15,880,469 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 646.7K   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

 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
Peter Carnegie2-Feb-06 7:22
Peter Carnegie2-Feb-06 7:22 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
ufo9738-Nov-07 4:42
ufo9738-Nov-07 4:42 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
kaaviya18-Jun-09 23:53
kaaviya18-Jun-09 23:53 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
Ernesto Danton21-Feb-06 10:14
Ernesto Danton21-Feb-06 10:14 
QuestionRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
NMIB22-Jan-07 9:38
NMIB22-Jan-07 9:38 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
S_JAYASURIYA8-Feb-07 6:32
S_JAYASURIYA8-Feb-07 6:32 
GeneralRe: THE TEXT-TO-SPEECH VB SAMPLE Pin
Hemant Chauhan12-Mar-07 5:33
Hemant Chauhan12-Mar-07 5:33 
GeneralI need a source code about MS IP conferrence Pin
nhbach220312-Oct-05 17:10
nhbach220312-Oct-05 17:10 
Generalfrequently asked question Pin
Anonymous9-Oct-05 20:17
Anonymous9-Oct-05 20:17 
GeneralTTS Project Pin
sinansoycan9-Oct-05 12:10
sinansoycan9-Oct-05 12:10 
GeneralDirectSS Pin
dragonjim3-May-05 15:35
dragonjim3-May-05 15:35 
GeneralRe: DirectSS Pin
rockbyte29-Jul-05 13:35
rockbyte29-Jul-05 13:35 
GeneralI made it work Pin
Ernesto Danton21-Feb-06 10:15
Ernesto Danton21-Feb-06 10:15 
Questionhow to speak in other language like Hindi,Bengali in test to sppch Engine Pin
princei20072-May-05 11:53
princei20072-May-05 11:53 
Generalhelp to control parallel lpt port using voice recogniton Pin
tech_abhishek28-Apr-05 7:24
tech_abhishek28-Apr-05 7:24 
Generalharkmaster Pin
harkamster18-Feb-05 10:11
harkamster18-Feb-05 10:11 
Generalspeech module doesnt speak Pin
sarmila raja25-Nov-04 18:36
sarmila raja25-Nov-04 18:36 
GeneralMalay Talking Dictionary Pin
ain288212-Sep-04 19:41
ain288212-Sep-04 19:41 
GeneralRe: Malay Talking Dictionary Pin
diamonddust_6728-Sep-04 7:17
diamonddust_6728-Sep-04 7:17 
QuestionHow can I change to Thai language Pin
sungkom16-Jul-04 22:40
sungkom16-Jul-04 22:40 
AnswerRe: How can I change to Thai language Pin
JitklaSamart29-Mar-06 4:28
JitklaSamart29-Mar-06 4:28 
Generalrecongnition Pin
sinmorn24-May-04 14:52
sinmorn24-May-04 14:52 
QuestionHow to convert text to chart Pin
hitomi_fiz20-May-04 17:15
hitomi_fiz20-May-04 17:15 
AnswerRe: How to convert text to chart Pin
ram babu kvs26-Oct-04 6:58
ram babu kvs26-Oct-04 6:58 
GeneralAdjst the volume and speed Pin
fanmen21-Apr-04 8:02
fanmen21-Apr-04 8:02 

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.