请求 Google Text-To-Speech API [英] Request to Google Text-To-Speech API

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

问题描述

我有这个网址:http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world当我把它放到浏览器的地址栏并按回车键时,我会得到带有合成语音的 mp3 文件,上面写着Hello world".一切正常.

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.

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

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>

当我点击这个链接时,我没有得到一个文件,而是一个错误(简单的 QuickTime 标志).谁能解释一下为什么会这样,我该如何解决我的问题?

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?

推荐答案

解释是谷歌限制了这个服务的使用:根据this StackOverflow answer,如果 HTTP 请求包含 Referer 标头,Google 会返回 404 错误a> 非空字符串.

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.

当您在地址栏中输入 URL 时,没有问题,因为不会将 Referer URL 传输到 Google.当您点击超链接时,您就有了一个引荐来源,而 Google 会阻止您的请求.

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.

注意:我测试了您的网址(请参阅 这里),它奏效了.我怀疑这只是因为我之前在地址栏中键入 URL 尝试过,而该资源仍在我的浏览器缓存或音频插件 (VLC) 缓存中.

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:请参阅此处 寻求解决方法.

NB2: See here for a workaround.

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

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