27模块-speech【语音转文字功能,例如语音识别】

Speech模块管理语音输入功能,提供语音识别功能,可支持用户通过麦克风设备进行语音输入内容。通过plus.speech可获取语音输入管理对象。

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>心得</title>
<script type="text/javascript">
var text;
function one(){
//只要是语音识别统一用{engine:'iFly'}就行了
plus.speech.startRecognize({engine:'iFly'},function(str){
//text = str;
document.getElementById("imglist").innerHTML = "<li style='color:red'>刚才识别到的语音内容是:"+str+"</li>";
},function(e){
alert('语音识别失败:'+e.message);
});
}
function two(){
plus.speech.stopRecognize();
}
function three(){
alert(text);
}
</script>
</head>
<style>
li{line-height: 40px; height: 40px; border-bottom: #ccc dashed 1px;}
</style>
<body>
<ul id="imglist"></ul>
<ul>
<li onclick="one()">启动语音识别</li>
<li onclick="two()">停止语音识别(几乎不用)</li>
<li onclick="three()">查看语音信息(几乎不用)</li>
</ul>
</body>
</html>

 

posted @ 2018-07-18 19:34  学画人生  阅读(1224)  评论(0编辑  收藏  举报