HTML5语音输入和谷歌翻译的文本 - 语音转换,问题在Chrome [英] HTML5 speech input and Google Translate text-to-speech, problem in Chrome

查看:330
本文介绍了HTML5语音输入和谷歌翻译的文本 - 语音转换,问题在Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个语音/文本备忘录Web应用程序。
在这里: http://gustavstromberg.se/sandbox/html5/localstorage/ 看它的源代码(很短,大部分是CSS)

I'm creating a voice/text-memo web application. Here: http://gustavstromberg.se/sandbox/html5/localstorage/ look at its source (very short, most of it is css)

这是:


  • 语音识别,只能在Chrome中,据我所知。

  • 本地存储,以笔记存储为文本。

  • 谷歌翻译的文本 - 语音转换。

一切正常,但在不同的浏览器。声音输入运行完美,只是在镀铬。文本 - 语音转换工作在Safari浏览器。

Everything works, but in different browsers. The voice input works perfect, only in chrome. The text-to-speech works in safari.

要备忘录动态加载到音频>源元素使用:

To dynamically load the memo into the audio>source element i use:

$("#spokenmemory").html("<source src='http://translate.google.com/translate_tts?tl=en&q="+localStorage['memory']+"' />");

(在localStorage的['记忆']包含我的存储文本提示)

(the localStorage['memory'] contains my stored text memo)

要发挥我最近保存的备忘录与谷歌文本到语音的功能,我使用的:

To play my recently saved memo with googles text-to-speech-function I use:

$("#listenplay").click(function(){
    $("#spokenmemory")[0].play();
});

(spokenmemory是我的音乐标签的ID属性)

(spokenmemory is the id-attribute of my audio-tag)

这一点儿也不工作,在Chrome中播放,但如果我访问的翻译链接(例如:的 http://translate.google.com/translate_tts?tl=en&q=Japan ,我的文字备忘录是日本制造),在一个单独的浏览器选项卡,然后返回到我的网站并重新加载页面(具有相同文本的备忘录,日本保存),播放的作品。真奇怪,和annying!

This does'nt work to play in chrome, but if I visit the translation link (example: http://translate.google.com/translate_tts?tl=en&q=Japan, and my text-memo is "Japan") in a separate browser-tab and then return to my site and reload the page (with the same text-memo "Japan" saved), the playback works. How strange, and annying!

有没有人的这种奇怪的行为任何想法?

Has anyone any idea of this strange behaviour?

推荐答案

这是因为谷歌限制某些类型的请求,以prevent被超载的服务。因此,当浏览器尝试获取它的音频文件不是空穴来风。一旦您访问翻译链接,音频文件被取出并缓存这就是为什么播放作品(提供的文本备忘录是一样的)。这一直是我的观察,但我不是很肯定。

It is because google restricts certain types of requests to prevent the service from being overloaded. So the audio file is not fetched when your browser tries to fetch it. Once you visit the translation link, the audio file is fetched and is cached which is why the playback works (provided the text-memo is same). This has been my observation but I'm not very sure.

当我用卷曲来获取文件,这就是我得到了响应:

When I used CURL to fetch the file, this is what I got in response:

403 这是一个错误。

您的客户端无权从该服务器获取网址 / translate_tts?Q =你好

这篇关于HTML5语音输入和谷歌翻译的文本 - 语音转换,问题在Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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