Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request to Google Text-To-Speech API [closed]

I have this URL: http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world When I put it to the address bar in a browser and hit enter, I get mp3 file with synthesized speech saying "Hello world". Everything is correct.

But now I have a link in HTML that redirects to this URL, like this:

<a href="http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world">Link</a>

When I click this link, I don't get a file but an error (simple QuickTime logo). Could anyone explain me why is it so and how can I solve my problem?

like image 297
Piotr Chojnacki Avatar asked Oct 14 '12 14:10

Piotr Chojnacki


1 Answers

The explanation is that Google restricts the usage of this service: according to this StackOverflow answer, Google returns a 404 error if the HTTP request contains a Referer header other than an empty string.

When you type the URL in the address bar, it's ok because no Referer URL is transmitted to Google. When you click on a hyperlink, you have a referer and Google blocks your request.

NB: I tested your URL (see here), and it worked. I suspect that it was only because I have tried before by typing the URL in my address bar, and the resource was still in my browser cache or in my audio plugin (VLC) cache.

NB2: See here for a workaround.

like image 188
olivierlemasle Avatar answered Oct 22 '22 02:10

olivierlemasle