HTML成功获取录入音频后,如何仍将音频转为文字,在网页输出

qq_38798367 2017-05-16 11:26:29
这是我目前的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="js/jquery.js"></script>
</head>
<body>
<script>
var audioCtx;
try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
} catch (e) {
console.log("Your browser does not support AudioContext!");
}
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); // 使用音频(0或者1)和(0或者1)视频输入设备
if (navigator.getUserMedia) {navigator.getUserMedia({ audio : true}, function(stream) {

var SpeechRecognition = window.SpeechRecognition|| window.mozSpeechRecognition|| window.webkitSpeechRecognition || window.msSpeechRecognition|| window.oSpeechRecognition;
if (SpeechRecognition) {
alert("SpeechRecognition Over");
var speechRecognition = new SpeechRecognition(); //创建一个 speechRecognition的实例,将语音转换为文本
speechRecognition.addEventListener("result", function(stream) {
var results = stream.results;
if (results.length > 0) {
for (var i = 0; i < results.length; i++) {
alert(results[i][0].transcript);
console.log(results[i][0].transcript);
$("body").html($("body").html()+results[i][0].transcript);
}
}
}, false);
speechRecognition.continuous = true;
speechRecognition.start();
}

var source = audioCtx.createMediaStreamSource(stream); // 获取媒体流
var biquadFilter = audioCtx.createBiquadFilter(); // 建立双二阶滤波器
biquadFilter.type = "lowshelf"; // 低段滤波
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = 25; // 增益
source.connect(biquadFilter);
biquadFilter.connect(audioCtx.destination); //

}, function(err) {
console.log("The following gUM error occured: " + err);
});
} else {
console.log("getUserMedia not supported on your browser!");
}
</script>
</body>
</html>
...全文
172 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,985

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧