网页前端设计

http://www.86y.org

搜索文章

把文章用声音读出来(研究中)

用声音读出全文关注我吧
 2012/9/3 10:28:51 阅读次数:6416

把内容用声音读出来(研究中)

前几天看到有个网站可以阅读所选文字并读出来,感觉如果一篇小说全部让声音读出来那会不会更好呢!

其实这只是我的想像,经过多次实验,不过由于翻译字数有限(2000)字以内,一篇文章截成若干份,播放完一段后再用下一份去调用声音API,因为无法取到播放完后返回一个值,然后依此类推,其中是用mircosoft的获取声音API返回打包好的mp3格式的!利用flash播放器读取并播放。

获取中/英文字声音的 API,以下获取的是“hello nice to meet you”的声音。

http://api.microsofttranslator.com/V2/http.svc/Speak?appId=T-27gIGHrAHICUnQ4a2DmVvPFqgW4RApStTESP4ZjAu0*&text=hello+nice+to+meet+you&language=en&format=audio/mp3

实例代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>把内容用声音读出来</title>
<!--[if IE 6]><style type="text/css">*html{background-image: url(about:blank);background-attachment: fixed;}</style><![endif]-->
<style>
#frameBOX{display:none;padding:0 5px 5px;width:400px;height:430px;border:1px solid #ddd;background:#eee;position:absolute;bottom:0;right:0;font-size:12px;position:fixed;/*固定定位*/_POSITION: absolute;/*兼容IE6*/_TOP: expression(offsetParent.scrollTop+document.documentElement.clientHeight-this.offsetHeight);/*兼容IE6*/z-index:9999;height:}
</style>
<script>
function Dusound(id){
	var ale=document.getElementById(id).value;
	document.getElementById("frameBOX").style.display="block";
	document.getElementById("sd").src="http://www.aihuaci.com/du/index.aspx?key="+ale+"&webid=190&url=www.baidu.com&title=%E6%90%9C%E7%B4%A2";
}
function Gusound(){
	document.getElementById("frameBOX").style.display="none";document.getElementById("sd").src="";
}
</script>
</head>
<body>
<div id="frameBOX">
	<div style="height:30px;line-height:30px;"><b>发音</b><a href="javascript:Gusound();" style="position:absolute;top:0px;right:10px;">半闭</a></div>
	<iframe id="sd" src="" style="width:400px;height:400px;background:#fff;" frameborder="0" scrolling="auto"></iframe>
</div>
<textarea name="dd1" cols="60" rows="10" id="dd1">现在的中国进入了对家庭教育非常复杂的时代,社会里面有标准,家庭里面有标准,而且,这些标的</textarea><br />
<a href="javascript:Dusound('dd1');">读出以上文字内容</a><br />
<textarea name="dd2" cols="60" rows="10" id="dd2">Now China has entered the era of family education is very complex social inside a standard family there are standards, and these standards may be wrong standard. For example, our standard is to require child class into the top five, as long as the kids can be admitted to Peking University, Tsinghua Even if successful, to Harvard, Yale, the more successful. Although this is the standard, but in my opinion, are the wrong standard.</textarea><br />
<a href="javascript:Dusound('dd2');">读出以上文字内容</a>
<br />
<textarea name="textbox" cols="60" rows="10" id="textbox">hello nice to meet you</textarea><br />
<a href="javascript:Dusound('textbox');">读出以上文字内容</a>
<div id="dd3" style="height:1000px;"></div>
</body>
</html>

结语:

难点:一个flash声音播放器放完调用页面的JS即可实现小说用声音阅读的功能,还有一个问题是等待问题文章如果内容太多会加载声音比较长

希望大家可以相互研究这个话题,我觉得这个做法对于盲人来说是非常好一个效果,或者你不想看可以休息下来听听这个文章!期待大家来的参与!


大家有什么问题或技术上的想法可以在此与大家分享,也可以加入前端爱好者QQ群(141999928)一起学习进步:【幸凡前端技术交流群】
0

如果您觉得本文的内容对您的学习有所帮助,捐赠与共勉,支付宝(左)或微信(右)

相关文章

阅读全文内容关闭