Search code examples
htmlaudiotext-to-speechgoogle-translate

Google Translate TTS problem


I'm testing with a simple HTML file, which contains:

<audio src="http://translate.google.com/translate_tts?tl=en&q=A+simple_text+to+voice+demonstration." controls autoplay>

with Chrome v11.0.696.68 and FF v4.0.1. I'm going through a proxy server and it doesn't work. Nothing gets played and clicking on the play button doesn't work in Chrome. In FF it flashes and then shows an 'X' over the control. The error logs don't show anything.

So I've broken down the steps:

  1. Typing the URL into either browser works

  2. wget -q -U Mozilla -O /tmp/tts.mp3 "http://translate.google.com/translate_tts?tl=en&q=Welcome+to+our+fantastic+text+to+voice+demonstration." gets me a file that plays fine on both browsers.

  3. If I serve this file from my local web server it works fine (i.e. one that doesn't go through the proxy). i.e. src="http://localhost/tts.mp3"

I'm stumped. If the proxy were the problem then wget and address bar access shouldn't work. If the src being a URL were the problem then it shouldn't work from my local server.

Any clues? suggestions?


Solution

  • The reason this isn't working is most likely because translate.google.com restricts certain types of requests to prevent the service from being overloaded. For instance, if you use wget without the "-U Mozilla" user agent option you will get an HTTP 404 because the service restricts responses from wget's default user agent string.

    In your case, it looks like what is going on is that translate.google.com is returning a HTTP 404 if a HTTP Referrer is included in the request. When you run wget from command line there is no referrer. When you use the audio tag from within a webpage, an HTTP Referrer is provided when requesting the translation. I just tried the following and got a 404.

    wget --referer="http://foo.com" -U Mozilla -O /tmp/tts.mp3 "http://translate.google.com/translate_tts?tl=en&q=Welcome+to+our+fantastic+text+to+voice+demonstration
    

    However if you take the --referer option out, it works.