Click here to Skip to main content
Licence 
First Posted 23 Nov 2001
Views 440,634
Bookmarked 67 times

Text-To-Speech

By | 27 Nov 2001 | Article
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.

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

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:

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

About the Author

AlexanderRegueiro



United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNot working PinmemberSjnilan7:27 13 Mar '12  
QuestionPlease, send me source too PinmemberRaimond S23:05 29 Nov '11  
QuestionABOUT THE TEXT TO SPEECH PROJECT Pinmembermadhuramanojjoshi19:59 14 Jul '11  
Generalsend me the source code Pinmemberchintan27900:56 7 Mar '11  
GeneralRe: send me the source code Pinmembersrikantharumilli7:04 8 Sep '11  
GeneralMy vote of 1 PinmemberNaren83.Freak6:41 21 Oct '10  
GeneralMy vote of 1 Pinmemberrahuluttarkar1:19 11 Oct '10  
GeneralMy vote of 5 Pinmemberwalter galotta20:47 18 Jul '10  
Generaltext to speech PinmemberMember 373269322:28 20 May '10  
GeneralNice Tutorial Pinmembersankaranandan20:57 6 Mar '10  
Generalsir i am geting compiler error : method or data member not found Pinmemberchistiforu_2k514:57 16 Dec '09  
GeneralNo Voice PinmemberGurinder Pal21:48 15 Dec '09  
GeneralMy vote of 1 PinmemberKumar Umang Gupta2:17 21 Oct '09  
AnswerRe: My vote of 1 PinmemberMember 41561274:23 18 Nov '09  
QuestionWhat's true? Pinmemberbeibut7:01 17 Oct '09  
GeneralProblem solved. Thank you Pinmemberjohnius1:57 17 Mar '09  
GeneralHELP PLEASE.... PinmemberMary May19:20 26 Sep '08  
Generalnot responding well Pinmemberramcse6:02 8 May '08  
GeneralNo sound PinmemberBrunoCoimbra8:34 15 Apr '08  
Questionno sound appear Pinmemberkimodiab10:11 6 Apr '08  
QuestionText to Speech converter(olife) Pinmemberolyad3:48 25 Mar '08  
Generalhelp: Changing voice Pinmembercraver0616:54 4 Oct '07  
GeneralRe: help: Changing voice Pinmemberkiller angelo6:34 17 Oct '07  
Generaltts for malay language Pinmemberzuwie7:12 28 Aug '07  
GeneralHelp Me.......... Pinmembernay3315518:20 20 Jun '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 28 Nov 2001
Article Copyright 2001 by AlexanderRegueiro
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid