谷歌翻译 TTS 问题
我正在使用一个简单的 HTML 文件进行测试,其中包含:
。我正在通过代理服务器,但它不起作用。 Chrome 中没有播放任何内容,并且单击播放按钮也不起作用。在 FF 中,它会闪烁,然后在控件上显示一个“X”。错误日志没有显示任何内容。
因此,我分解了这些步骤:
在任一浏览器中键入 URL 都有效
wget -q -U Mozilla -O /tmp/tts.mp3 "http: //translate.google.com/translate_tts?tl=en&q=欢迎+to+our+fantastic+text+to+voice+demonstration。"为我提供一个在两种浏览器上都能正常播放的文件。
如果我从本地网络服务器提供此文件,它可以正常工作(即不通过代理的文件)。即 src="http://localhost/tts.mp3"
我被难住了。如果代理是问题所在,那么 wget 和地址栏访问应该不起作用。如果 src 是 URL 是问题所在,那么它不应该在我的本地服务器上工作。
有什么线索吗?建议?
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:
Typing the URL into either browser works
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不起作用的原因很可能是因为translate.google.com限制了某些类型的请求以防止服务过载。例如,如果您使用不带“-U Mozilla”用户代理选项的 wget,您将收到 HTTP 404,因为该服务限制来自 wget 的默认用户代理字符串的响应。
在您的情况下,如果请求中包含 HTTP Referrer,translate.google.com 就会返回 HTTP 404。当您从命令行运行 wget 时,没有引用者。当您在网页中使用音频标签时,请求翻译时会提供 HTTP Referrer。我刚刚尝试了以下操作并得到了 404。
但是,如果您去掉 --referer 选项,它就可以工作。
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.
However if you take the --referer option out, it works.
该服务在此运行(2011 年 11 月 11 日),但字符数限制为 100 个。您可以将文本拆分为 100 个字符的块,下载每个块的 mp3 结果,然后将这些块连接起来形成最终的 Mp3 文件。
The service is working here (11-NOV-2011) but is limited to 100 characters. 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.