Text to Speech | Synthesizer in PHP

I hope you all are well and enjoy my blog.
After long time a write a one blog for my best blog reader.

This post is regarding to text to speech. Its simply speech synthesizer. There are many things available but its limited to free.(open source).
In, this blog there is a free open source script for text to speech (Synthesizer) for all programming language. But for now I’m using PHP language for demo | example.

Here, there are many script for text to speech but mainly there are using other server for transferring the audio from third party server to own server.So, its take a time to execution | transferring the voice speech.
For example : Google, ResponsiveVoice.JS and many others.

There are many providers of Speech Synthesizer but mostly are paid , non-paid for non-commercial use , open source.
For example : Responsivevoice JS, Codecanyon Text To speech php js script, Espeak Sourceforge

Here, I’m using Espeak Sourceforge software because this is a free and open source.

Requirement:

Documents:

  • http://espeak.sourceforge.net/commands.html
  • http://espeak.sourceforge.net/docindex.html

Steps:

  1. Download Software & install it. (If you are using windows then you can use windows install file otherwise you can use mac-os x or linux.)
  2. Set Path for “C:\Program Files (x86)\eSpeak\command_line”  espeak.exe  using environment variable.
    Set Path in Environment
    Set Path in Environment

    3. Check your path in command prompt:

    Check set path in cmd
    Check set path in cmd

     

    4. You can use text to speech (espeak) command directly to command prompt.
    For Example :  espeak “Darshak Shah”

    You can use many options like change voice of speaker, language, pitch etc… (Please refer document section for that).

    or 4. You can use this function (espeak) in any programming language.
           For Example (PHP) :

    <?php
    $rand=rand();
    $text="Darshak Shah";
    shell_exec('espeak -ven-us+f5  -z -s 160  -w "audio\\test\\'.$rand.'.wav" "'.$text.'"');
    ?>

    Here, where : shell_exec()  is a function to call any external program from php.
    espeak : is a command
    -ven-us+f5  : -v is use for change the language | en-us for usa english and +f means female voice |   5 means version of female voice
    (please refer document section for more details of parameter)
    -w : save audio file into wav files

    Download Demo

    I hope you understand this tutorial. If you have any questions or confusion then please comment it.

 

 

 

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *