I love Lazarus. But sometimes I find that resources for Lazarus is very scarce. Also the weird fact is there are many programers who know many things but are not interested to share that in the form of tutorials or sample codes. That's why we have to use code from Delphi sites (which is sad).
I am still a newbie even after over 1 year of exposure to Lazarus (due to busyness I guess). But I want to share this little piece of knowledge to this community for any benefit that may come.A more detailed tutorial (for newbies) can be found here: http://inkoflife.blogspot.com/2013/03/let-your-software-speak.html
(EDIT: Further info and command line parameter details can be found here:
http://wiki.lazarus.freepascal.org/espeak )
Step 1:Download and install eSpeak from here:
http://espeak.sourceforge.net/download.htmlThe file should be named something like: espeak-1.46.02-win.zip
Create a directory where you will save the source code for the program. For example, D:\LazarusCodes\TTS-eSpeak-Test
Assuming that you installed eSpeak in the default installation directory C:\Program Files\eSpeak , now copy the installation folder to D:\LazarusCodes\TTS-eSpeak-Test. Thus you will have a D:\LazarusCodes\TTS-eSpeak-Test\eSpeak\command_line directory.
You may now uninstall eSpeak (we will use --path parameter to specify espeak-data directory which will allow us to use eSpeak in the stand alone mode, which will allow the user to use eSpeak even when it is not installed! It is a rather portable option. Cool, right?!)
Step 2: Code in Lazarus1. Open Lazarus.
2. Create a new Project.
3. Toggle to form design mode (F12). Drop a TMemo and a TButton in the form.
4. Also go to System tab and add a TProcess in the form. Set the Options to [poUsePipes] (Click the arrow/plus on the left and set poUsePipes to true). Also set Show Window to swoHIDE. (swoHide option hides the console window when running the command line tool.)
5. Write the following code:
procedure TForm1.Button1Click(Sender: TObject);
begin
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' +
' "' + Memo1.Text + '"';
Process1.Active:=True;
end;
6. File -> Save All and save your project in the directory D:\LazarusCodes\TTS-eSpeak-Test.
Step 3: Run and testPress F9 to compile and see the program how it works. Write something in the Memo and press the button. You will hear your words spoken. You may customize the interface (add images, speedbuttons, change captions etc.) and Run (F9) again.
Step 4: Enhance the code (Optional)Sometimes when the user enters large text often there is need to stop the speaking. You can drop another TButton (or TSpeedButton or TBitButton .... ) and double click it. Then write the command:
Process1.Terminate(0);
You can also drop a TEdit on the form and use it to specify further parameters to modify speed, pitch, volume, word gap and many other options of the spoken text. Now the Button1 command may change like this (or anything else, come on you are the programer!):
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' + Edit1.Text + ' ' +
' "' + Memo1.Text + '"';
Command line parameters are available here:
http://espeak.sourceforge.net/commands.htmlReference / Assistance:http://www.rolfware.de/delphi/espeak_example.htmlhttp://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.htmlhttp://www.mail-archive.com/lazarus@lists.lazarus.freepascal.org/msg26498.html