谷歌翻译 TTS 问题

发布于 2024-11-08 07:33:10 字数 594 浏览 3 评论 0原文

我正在使用一个简单的 HTML 文件进行测试,其中包含:

。我正在通过代理服务器,但它不起作用。 Chrome 中没有播放任何内容,并且单击播放按钮也不起作用。在 FF 中,它会闪烁,然后在控件上显示一个“X”。错误日志没有显示任何内容。

因此,我分解了这些步骤:

  1. 在任一浏览器中键入 URL 都有效

  2. wget -q -U Mozilla -O /tmp/tts.mp3 "http: //translate.google.com/translate_tts?tl=en&q=欢迎+to+our+fantastic+text+to+voice+demonstration。"为我提供一个在两种浏览器上都能正常播放的文件。

  3. 如果我从本地网络服务器提供此文件,它可以正常工作(即不通过代理的文件)。即 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:

  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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水晶透心 2024-11-15 07:33:11

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

在您的情况下,如果请求中包含 HTTP Referrer,translate.google.com 就会返回 HTTP 404。当您从命令行运行 wget 时,没有引用者。当您在网页中使用音频标签时,请求翻译时会提供 HTTP Referrer。我刚刚尝试了以下操作并得到了 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

但是,如果您去掉 --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.

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.

掌心的温暖 2024-11-15 07:33:11

该服务在此运行(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文