请求Google文字转语音API [英] Request to Google Text-To-Speech API

查看:147
本文介绍了请求Google文字转语音API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网址: http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world
当我将它放到浏览器的地址栏中并按下回车键时,我会收到带有合成语音的MP3文件,内容为Hello world。一切都是正确的。



但现在我有一个HTML链接重定向到这个URL,像这样:

 < a href =http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world>连结< / a> ; 

当我点击这个链接时,我没有收到一个文件,而是一个错误(简单的QuickTime标志) 。任何人都可以解释我为什么这样,我该如何解决我的问题?

解决方案

解释是Google限制了此服务:根据此StackOverflow答案,如果HTTP请求包含 Referer header



当你键入地址栏中的网址,因为没有Referer网址传送给Google,所以没关系。当你点击一个超链接时,你有一个引用者,Google会阻止你的请求。



注意:我测试了你的URL(参见这里),并且工作。我怀疑这只是因为我之前通过在地址栏中键入URL来尝试,而资源仍然在我的浏览器缓存或音频插件(VLC)缓存中。



NB2:请参阅此处 a>解决方法。


I have this URL: http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world When I put it to the address bar in a browser and hit enter, I get mp3 file with synthesized speech saying "Hello world". Everything is correct.

But now I have a link in HTML that redirects to this URL, like this:

<a href="http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world">Link</a>

When I click this link, I don't get a file but an error (simple QuickTime logo). Could anyone explain me why is it so and how can I solve my problem?

解决方案

The explanation is that Google restricts the usage of this service: according to this StackOverflow answer, Google returns a 404 error if the HTTP request contains a Referer header other than an empty string.

When you type the URL in the address bar, it's ok because no Referer URL is transmitted to Google. When you click on a hyperlink, you have a referer and Google blocks your request.

NB: I tested your URL (see here), and it worked. I suspect that it was only because I have tried before by typing the URL in my address bar, and the resource was still in my browser cache or in my audio plugin (VLC) cache.

NB2: See here for a workaround.

这篇关于请求Google文字转语音API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆