简体   繁体   English

谷歌翻译 TTS 问题

[英]Google Translate TTS problem

I'm testing with a simple HTML file, which contains:我正在使用一个简单的 HTML 文件进行测试,其中包含:

<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.使用 Chrome v11.0.696.68 和 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.什么都没有播放,点击播放按钮在 Chrome 中不起作用。 In FF it flashes and then shows an 'X' over the control.在 FF 中,它会闪烁,然后在控件上显示一个“X”。 The error logs don't show anything.错误日志不显示任何内容。

So I've broken down the steps:所以我分解了步骤:

  1. Typing the URL into either browser works在任一浏览器中输入 URL 都有效

  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." 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 (ie one that doesn't go through the proxy).如果我从本地 Web 服务器提供此文件,则它可以正常工作(即不通过代理的服务器)。 ie src="http://localhost/tts.mp3"即 src="http://localhost/tts.mp3"

I'm stumped.我难住了。 If the proxy were the problem then wget and address bar access shouldn't work.如果代理是问题,则 wget 和地址栏访问不应该工作。 If the src being a URL were the problem then it shouldn't work from my local server.如果 src 是一个 URL 是问题,那么它不应该在我的本地服务器上工作。

Any clues?有什么线索吗? suggestions?建议?

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.这不起作用的原因很可能是因为 translate.google.com 限制了某些类型的请求以防止服务过载。 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.例如,如果您使用没有“-U Mozilla”用户代理选项的 wget,您将收到 HTTP 404,因为该服务限制来自 wget 的默认用户代理字符串的响应。

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.在您的情况下,如果请求中包含 HTTP Referrer,那么 translate.google.com 似乎正在返回 HTTP 404。 When you run wget from command line there is no referrer.当您从命令行运行 wget 时,没有引用。 When you use the audio tag from within a webpage, an HTTP Referrer is provided when requesting the translation.当您在网页中使用音频标签时,会在请求翻译时提供一个 HTTP Referrer。 I just tried the following and got a 404.我刚刚尝试了以下方法并得到了 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.但是,如果您去掉 --referer 选项,它就可以工作。

The service is working here (11-NOV-2011) but is limited to 100 characters.该服务在此运行 (2011 年 11 月 11 日),但仅限于 100 个字符。 You can split your text into 100 char chunks, download the mp3 result for each chunk and then join the chunks for the final Mp3 file.您可以将文本拆分为 100 个字符块,下载每个块的 mp3 结果,然后将这些块合并为最终的 Mp3 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM