在服务器上播放HTML5中的远程音频(来自谷歌翻译)

Tom*_*che 8 html javascript html5 text-to-speech google-translate

我正在尝试使用HTML5和Google翻译在网站上使用文字转语音.

从Google获取演讲就像GET请求一样简单:http: //translate.google.com/translate_tts?tl = en&q = hello

为了播放该文件我正在使用audio-tag:

<audio id="speech" src="http://translate.google.com/translate_tts?tl=en&q=hello" controls="controls" autoplay="autoplay">Your browser does not support the audio element.</audio>

当我尝试使用Chrome 11在本地打开html文件时,这非常有效,但是当我从服务器打开html时它根本不起作用...它只是没有做任何事情(播放按钮闪烁一秒钟,但没有任何反应).

您可以在此处找到该文件:http://www.announcify.com/chrome/background.html

有任何想法吗?:)
汤姆

MKN*_*ons 2

确保您的 rel 标签设置正确。谷歌可能有跨域保护。

  • 我已经进行了测试,所有浏览器都会失败。以下是最有可能起作用的方法:创建一个本地 php 文件(当然,然后上传到您的服务器),以便您的标记为 src="audio.php"。然后,在audio.php文件中,将该php文档设置为google url的file_get_contents;您可能需要将标头设置为音频/mpeg。这应该够了吧。 (7认同)
  • 哇!有用!非常感谢。:) PHP 代码: `$voice = file_get_contents('http://translate.google.com/translate_tts?tl=en&amp;q=hello'); 回声$声音;` (6认同)