使用 jquery 的 Google 文本转语音 onclick - 跨浏览器实现

发布于 2024-12-05 06:14:21 字数 341 浏览 1 评论 0原文

使用之前的 SO 答案,我已将 TTS 集成到此处的网站中:http://access。 mwjt.co.uk/feedback/tts.php

在 Chrome 中工作正常,但在任何其他浏览器中不行 - 谁能解释一下为什么?

我已将代码放入此处的小提琴中: http://jsfiddle.net/Mje3n/ 但是,这无法在任何浏览器上运行...???

非常感谢

Using a previous SO answer I've integrated TTS into a website here: http://access.mwjt.co.uk/feedback/tts.php

Works fine in Chrome, but not in any other browser - can anyone shed any light on why please?

I've put the code into a fiddle here: http://jsfiddle.net/Mje3n/ however, this isn't working on any browser...???

Many thanks

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

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

发布评论

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

评论(1

烟火散人牵绊 2024-12-12 06:14:21

单击页面中的按钮会出现 404 错误(未找到文件),该错误是从 Firefox 和 Safari 中的 Google 服务返回的,因此您听不到任何声音的主要原因是您没有收到响应。不过,有趣的是,如果我在浏览器中输入 Google 服务的 URL,音频文件就会返回。然后我转到 Chrome 查看其网络响应,发现它也返回 404 错误,但会再次尝试加载文件。这就是为什么它可以在 Chrome 中运行,而不能在其他网络浏览器中运行。

我尝试了一个非常非常基本的示例 像音频文件一样直接链接,但这在大多数情况下也失败Web 浏览器,因为 404 响应作为第一个回复返回,并且浏览器放弃加载文件。

Google 返回了这个 jQuery 插件示例,但也有跨浏览器即使使用 Flash 从 Google 服务加载 MP3,播放音频也会出现问题。如果您想这样做,您可能需要使用额外的服务或 Flash 中介来使 MP3/音频文件正常工作。

另一件需要考虑的事情是,这可能不适用于所有网络浏览器,因为不同的浏览器的行为不同。并非所有浏览器都支持 HTML5,并且需要不同的浏览器

虽然这无助于回答问题,但您可能应该考虑一些其他信息。您可能需要考虑使用 Microsoft 翻译服务而不是 Google 翻译服务。从 Google 代码的 jquery-translate 页面:

由于 Google Translate API 将于 2011 年 12 月 1 日完全关闭,此插件将使用 Microsoft Translator 服务

另外,来自 Google 翻译 v2 主页

重要提示:Google Translate API v2 现已作为付费服务提供。 2011 年 8 月 24 日之前创建的现有 Translate API v2 项目的礼貌限制将于 2011 年 12 月 1 日减少到零。此外,您的应用程序每天可以发出的请求数量也将受到限制。对于网站翻译,我们鼓励您使用 Google 网站翻译器小工具。

我不能 100% 确定这会影响文本转语音 (TTS) 服务,但它确实强烈建议这样做。它可能会得到缓刑,但如果规定了最后期限,我不会构建依赖于该服务的应用程序或网站,因为我知道它可能会消失。

Microsoft Translator 的文档中,有一个链接到来自服务的语音部分的 .wav 文件。

我希望所有这些信息有助于做出如何前进的决定,并祝您的项目好运。

Clicking on the button in the page gives me a 404 error (file not found) coming back from the Google service in Firefox and Safari, so the main reason you're not hearing anything is that you're not getting a response. Interesting thing, though, is if I put your URL to the Google service in a we browser the audio file does come back. I then went over to Chrome to see what its network response looked like and saw that it was also returning a 404 error, but would make a second attempt to load the file. This is why it is working in Chrome and not in other web browsers.

I tried a very, very basic example linking directly like it was an audio file but this also fails in most web browsers since the 404 response comes back as the first reply and the browser gives up loading the file.

Google returned this jQuery plugin example but, too, has crossbrowser issues playing the audio even though it uses Flash to load the MP3s from the Google service. If you want to do this, you may need to employ an additional service or Flash intermediary to get the MP3/audio file to work.

The other thing to consider there is that this may not work in all web browsers just because different browsers behave differently. Not all browsers support HTML5 and need different

Though this doesn't help answer the question, there is some additional info you should probably consider. You may want to consider using the Microsoft translator service instead of the Google one. From the jquery-translate page on Google Code:

Since the Google Translate API will be shut off completely on December 1, 2011 this plugin will use the Microsoft Translator service

Also, from the Google Translate v2 Homepage:

Important: Google Translate API v2 is now available as a paid service. The courtesy limit for existing Translate API v2 projects created prior to August 24, 2011 will be reduced to zero on Dec 1, 2011. In addition, the number of requests your application can make per day will be limited. For website translations, we encourage you to use the Google Website Translator gadget.

I can't be 100% sure this effects the Text to Speech (TTS) services but it does strongly suggest this. And it may get a reprieve, but if the deadlines are stated I wouldn't build an application or a website that relied upon the service knowing it is probably going away.

In the documentation for the Microsoft Translator there is an example for linking to a .wav file from the Speech portion of the service.

I hope that all this info is helpful in making a decision on how to go forward, and good luck with your project.

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