Categories
PHP

Google’s Text to Speech API : A PHP Wrapper Class

It’s really amazing how Google is providing cool APIs for every this and that! And here comes another one that impressed me 😀 I am talking about the Text To Speech API by Google. It’s fantastic! I wrote a php wrapper class that would help you create mp3 files from texts 🙂 Of course, using Google as the medium!

Here’s the source code:

And here’s demo :

You can alternatively pass the text to the constructor of the object like this:

That is simple, isn’t that? Hope you like it!

31 replies on “Google’s Text to Speech API : A PHP Wrapper Class”

Hello, if i would speech a text without limit of 100 char, how can i split the text and speech all one next another?

Let me know plz and sorry for my english.

Yes, my problem is how execute one after another the link that i have created.

how do I know when the execution of the first link is completed to start the second?

Thanks

i have modified this so it can support French, but when i tried to add some unique character in French like “Et vous êtes?” it won’t working correctly.. it sounds weird..

facing error in your code
Notice: Undefined variable: mp3data in E:\wamp\www\voice\tts.php on line 27

They haven’t blocked it, you just need to include the variable “tl=en” within the address.

So instead of it being:
file_get_contents("http://translate.google.com/translate_tts?q={$text}");

You will have to use:
file_get_contents("http://translate.google.com/translate_tts?tl=en&q={$text}");

That should work. 🙂

assalamualekum ,

can you please tell me how we convert our text to voice carrying more than 100 strings can you please help me with a proper procedure on it .

thankyou

( ! ) Parse error: syntax error, unexpected ‘World’ (T_STRING) in C:\wamp\www\t2s\index.php on line 5
This gives an error. Please find some solution as soon as possible.

Comments are closed.