Recent

Author Topic: Lazarus eSpeak TTS Example - Let your software speak!  (Read 26883 times)

nsunny

  • Full Member
  • ***
  • Posts: 117
  • Code is magic
    • LazPlanet
Lazarus eSpeak TTS Example - Let your software speak!
« on: March 06, 2013, 03:33:25 pm »
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.


Quote
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.html
The 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 Lazarus
1. 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:

Code: [Select]
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 test
Press 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:

Code: [Select]
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!):
Code: [Select]
  // 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.html

Reference / Assistance:
http://www.rolfware.de/delphi/espeak_example.html
http://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.html
http://www.mail-archive.com/lazarus@lists.lazarus.freepascal.org/msg26498.html
« Last Edit: March 07, 2013, 08:05:33 am by nsunny »
Lazarus TTS Tutorial | LazPlanet
Lazarus 2.2.0 | FPC 3.2.2 | Linux/OpenBSD/ReactOS

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #1 on: March 06, 2013, 03:39:20 pm »
Thanks - that looks nice.

However, could you please post tutorials on the wiki
http://wiki.lazarus.freepascal.org/espeak

... that makes it much easier to find them as well as edit/update them.

On the wiki you will also find an article for using SAPI (Windows Speech API) and IIRC also festival TTS.

Thanks
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #2 on: March 06, 2013, 03:50:20 pm »
The SAPI page is a starting point for TTS :
http://wiki.freepascal.org/SAPI

nsunny

  • Full Member
  • ***
  • Posts: 117
  • Code is magic
    • LazPlanet
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #3 on: March 07, 2013, 08:02:09 am »
Thanks BigChimp and theo. I have edited both the wikis.
Lazarus TTS Tutorial | LazPlanet
Lazarus 2.2.0 | FPC 3.2.2 | Linux/OpenBSD/ReactOS

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #4 on: March 07, 2013, 08:16:10 am »
Thanks nsunny, that was a great contribution!

I took the liberty of removing the duplicate code on the SAPI page - and mention it is cross-platform Linux+OSX as well!

Thanks a lot
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #5 on: March 07, 2013, 12:13:08 pm »
You can also import SAPI Voice as an Activex now (FPC trunk?)

I'll probably write a wiki about it when it is ready in FPC stable.

Looks like:

Code: [Select]
 
var
  SOToken: ISpeechObjectToken;
  SOTokens: ISpeechObjectTokens;
begin
  fSpVoice := TAxcSpVoice.Create(nil);
  fSpVoice.OnEndStream:=@fSpVoiceEndStream;
  fSpVoice.OleServer.Set_Rate(-3);
  SOTokens := fSpVoice.OleServer.GetVoices('', '');
etc...

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #6 on: March 07, 2013, 12:54:12 pm »
You can also import SAPI Voice as an Activex now (FPC trunk?)

I'll probably write a wiki about it when it is ready in FPC stable.
Go ahead - it is in FPC stable (2.6.2):
http://wiki.lazarus.freepascal.org/LazActiveX#Installing
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #7 on: May 19, 2013, 08:05:15 pm »
Hello  ;)
I have translated the original C header into Pascal.
It load dynamically the library and have reference counter.
I do not have test it on Windows.
If you need to install Portaudio, you may use the dynamic loader of portaudio too.

PS : In a near future, gonna add some example how to use it.

PS2 : Bye, bye ATK, AT-SPI and friends, i gonna do my way.  ;)

PS3 : @ Avra : many, many thanks for the tip, i feel free now to build a real assistive toolkit for LCL, fpGUI and Console app.
« Last Edit: May 19, 2013, 08:38:05 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #8 on: May 20, 2013, 07:39:57 am »
PS2 : Bye, bye ATK, AT-SPI and friends, i gonna do my way.  ;)
What if GTK users have festival installed or some commercial text to speech engine? Presumably ATK/AT-SPI is low level enough to use multiple engines at the user's choice.
See e.g.
https://developer.gnome.org/accessibility-devel-guide/stable/gad-how-it-works.html.en
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #9 on: May 20, 2013, 12:25:57 pm »
It's a good start, but best sample that sourceforge gave was this
http://espeak.sourceforge.net/samples/raven.ogg

If you can tweak the parameters to make it sound better, be my guest. But make sure to upload it to the samples to give espeak proper credit.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #10 on: May 20, 2013, 01:45:02 pm »
Chose promise, chose due.  ;)

Here examples with code and binaries how to use espeak.pas.
https://sites.google.com/site/fiensprototyping/ATfpGUI_LCL.tar.gz

Those demos are for Linux 64.

You do not need to install anything, the binaries (must) work "out of the box".
PS : It is a try for assistive access, so you may use the keyboard to test it.

@ BigChimp. You are the one i have the most respect here in that forum. Thanks for your help but AT-SPI is too difficult to understand. If is working a different way with Linux, Windows or Mac OS.
Lot of work to do it (not) work, no help, strange bad reactions. I prefer to develop my own accessibilty tool, accessible for everybody, simple and equal for each system.

PS : Everybody is welcome to follow me in that exiting travel.   ;)
« Last Edit: May 20, 2013, 01:51:32 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

esvignolo

  • Full Member
  • ***
  • Posts: 159
  • Using FPC in Windows, Linux, Macos
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #11 on: October 25, 2013, 03:30:47 am »
Hi Fred vS! the link for download isn't working, can you upload again?

Many thanks!


Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Lazarus eSpeak TTS Example - Let your software speak!
« Reply #12 on: October 25, 2013, 02:26:38 pm »
@ esvignolo :

Hello.

Take a look here :http://forum.lazarus.freepascal.org/index.php/topic,21174.0.html

sak GitHub sources :

http://fredvs.github.io/sak/

sak binaries demos :

https://sites.google.com/site/fiensprototyping/sk_bin_demos.zip

PS : You may use espeak.dll (and sak_dll) only if your program is open-source.
Otherwise you may use espeak.exe (and sak).

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018