top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to convert text to MP3 speech/Voice using Google API in PHP?

+2 votes
922 views

Please share the sample code?

posted Mar 17, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Text to voice conversion. To convert text to voice I have used Google TTS (Text to Speech) it will create an mp3 file and play it its a very simple script you must try its written in PHP it can convert almost 50+ languages. This Class converts text to speech using Google text to speech API to transform text to mp3 file which will be downloaded and later used as eg. embed file.

<?php
include 'PHP_Text2Speech.class.php'; 
    $t2s = new PHP_Text2Speech; 
?>
    <audio controls="controls" autoplay="autoplay"> 
       <source src="<?php echo $t2s->speak("Hello PHPGang");?>" type="audio/mp3" />    
    </audio>

Calling Google url to get mp3 file.

if (!file_exists($this->mp3File)) { 
            $this->download("http://translate.google.com/translate_tts?ie=UTF-8&q={$this->text}&tl={$this->lang}&total={$this->wordCount}&idx=0&textlen={$this->textLen}", $this->mp3File); 
        }
answer Mar 21, 2016 by Manikandan J
Similar Questions
+2 votes
0 votes

I want to retrieve the user's location after user signs in my website. How can I do that?

At this moment here is the scope that i have: $client->setScopes('email');
I guess I have to change that.

And to retrieve data I have the following:
$client->verifyIdToken()->getAttributes();

Do I need another method than this?

+3 votes

How can I convert the value of the speech rate value from Google's TTS into words per minute? Is there any direct relation between them, somewhere in the source code?

...