google tts with paid account

爱⌒轻易说出口 提交于 2019-12-11 06:49:23

问题


You now have to pay to use the google translate api. I'm happy to pay for the service but I can't find a way to use the tts. This is what I'm doing

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();      
  }
}

but when I do new GoogleTranslate().speak("hola")

The requests to http://translate.google.com/translate_tts never return a response. How do I get this working?


回答1:


I haven't tried your code yet, so I'm not sure if you should be waiting for the sound to load before you can play it (most likely), but I've written an article about this service recently. The part that matters here is the following:

...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...

Read the entire article here: Embedding text-to-speech into HTML5 games

So in fact, the service is still there, you just need to hide your referer header. One way to do that is through creating a small gateway script. There's the source for one right in the article.



来源:https://stackoverflow.com/questions/9763111/google-tts-with-paid-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!