How to convert text to MP3 speech/Voice using Google API
Today I am going to give you a great article on 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.
[wpdm_file id=23]DEMO
index.php
<?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); }
If you have any problem in using this code please write in comments and need your feedback.
Tutorial Categories:
How to convert mp3 to text?
this is great but would you like to tell me is this free for life time to use google api??
hi its michael cerasoli i’ve been a programmer since 1990 using windows and client server applications before 1990 using basic, and the Texas Instruments TRS-80. All these concepts have been around since then from 1995 to present things just started going down. But that’s ok, Microsoft’s 90 billion dollar industry certainly made up for it. And OFFICE is an incredibile product isn’t it? Man when windows came out I read every book the operating system came with about 15 manuals I read every one of them and never had to learn a thing since (with my mainframe, unix, db2, and c programming background of course). Anyway this is great and I thank you for all your wonderful time and support. 🙂
It’s always good to give out the completed code but hey let the programmer figure it out I don’t think anyone wants some “hack” to come in and steal the show am I right?
I just like to see the completed product you know syntax was always my problem in college anyway are you able to display the finished product, with html tags and all?
NOT ABLE TO DOWNLOAD EVEN I HAVE ALREADY SUBSCRIBE
Hi, the google translate text to speech has a character limit of 100. Can you post php code that will break longer text into chunks of 100 characters and join the mp3 files together in one mp3?
Your download subscription service is broken. Please fix or provide download
how can i use it its not working for me
can i have same thing without google api..
Example: in linux — espeak – cmd –
i cant see the download button… please fix it and thanx 4all