您现在必须付费才能使用 google translate api。我很乐意为这项服务付费,但我找不到使用 tts 的方法。这就是我正在做的
var GoogleTranslate = function(){
var key = "myapikey"
this.speak = function(words) {
var url = "http://translate.google.com/translate_tts?tl=es&q=" + escape(words) + "&key=" + key
new Audio(url).play();
}
}
但是当我执行 new GoogleTranslate().speak("hola") 时
对 http://translate.google.com/translate_tts 的请求永远不要回复。我如何让它工作?
最佳答案
我还没有尝试过您的代码,所以我不确定您是否应该等待声音加载后再播放(很有可能),但我最近写了一篇关于此服务的文章。这里重要的部分如下:
...if your browser forwards a Referer header with any value other than an empty string (meaning it tells the service which page you clicked the link on) then [Google] will return a 404 (Not Found) http error...
在此处阅读整篇文章:Embedding text-to-speech into HTML5 games
所以其实服务还在,你只需要隐藏你的referer header。一种方法是创建一个小型网关脚本。文章中有一项权利的来源。
关于javascript - 使用付费帐户的谷歌 tts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9763111/