In the Schahriar SaffarShargh response update, Google recently applied the “Google abuse” function, which makes it impossible to send just the plain old HTTP GET to a URL like:
http://translate.google.com/translate_tts?tl=en&q=Hello%20World
which worked just fine and dandy before. Now, after such a link, you represent CAPTCHA. This also affects HTTP GET requests outside the browser (e.g. cURL), as using this URL will redirect to the Anti-Malware (CAPTCHA) page.
To get started, you must add the client request parameter to the request URL:
http://translate.google.com/translate_tts?tl=en&q=Hello%20World&client=t
Google Translate sends &client=t , so you need one too.
Before making this HTTP request, make sure you set the Referer header:
Referer: http://translate.google.com/
Obviously, the User-Agent header is also required, but, interestingly, it may be empty:
User-Agent:
Edit : NOTE - for some user agents, such as Android 4.X, the custom User-Agent header is not sent, which means that Google will not serve the request. To solve this problem, I just set the User-Agent to a valid one, for example stagefright/1.2 (Linux;Android 5.0) . Use Wireshark to debug requests (like me) if Google’s servers aren’t responding and make sure these headers are set correctly in GET ! Google will respond with 503 Service Unavailable if the request fails and then redirects to the CAPTCHA page.
This decision is a bit fragile; it’s possible that Google will change the way these requests are handled in the future, so in the end I would suggest asking Google to make a real API endpoint (free or paid) that we can use without feeling dirty to fake HTTP headers.
Change 2 . For those who wish, this cURL command should work just fine to download mp3 Hello in English:
curl 'http://translate.google.com/translate_tts?ie=UTF-8&q=Hello&tl=en&client=t' -H 'Referer: http://translate.google.com/' -H 'User-Agent: stagefright/1.2 (Linux;Android 5.0)' > google_tts.mp3
As you can see, I set the Referer and User-Agent headers in the request, and also added the client=t parameter to the query string. You can use https instead of http , your choice!
Edit 3 : Google now requires a token for each GET request (marked tk in querystring). Below is a revised cURL command that will download mp3 TTS correctly:
curl 'https://translate.google.com/translate_tts?ie=UTF-8&q=hello&tl=en&tk=995126.592330&client=t' -H 'user-agent: stagefright/1.2 (Linux;Android 5.0)' -H 'referer: https://translate.google.com/' > google_tts.mp3
Note & tk = 995126.592330 in the request; this is a new token. I got this token by clicking the speaker icon on translate.google.com and looking at the GET request. I just added this querystring parameter to the previous cURL command and it works.
NOTE : Obviously, this solution is very fragile and breaks at the whim of Google architects who introduce new things, such as tokens needed for queries. This token may not work tomorrow (although I will check and send a report) ... The fact is that it is inappropriate to rely on this method; instead, turn to a commercial TTS solution, especially if you use TTS in production.
For a further explanation of marker generation and what you can do with it, see Boude's answer .
If this decision is violated at any time in the future, leave a comment on this answer so that we can try to find a fix for it!