首先,我正在尝试创建一个我不希望永远工作的临时解决方案。如果你愿意,只是一个实验!
我有以下运行!我想要做的是在页面加载时启动语音搜索。任何想法让这个工作!注意:您需要 chrome 浏览器才能看到麦克风输入。
http://jsfiddle.net/dirtyd77/99amf/
<html>
<head>
<style>
#mike {
font-size: 25px;
width: 25px;
height: 25px;
cursor:pointer;
border: none;
position: absolute;
margin-left: 5px;
outline: none;
background: transparent;
}
#txt {
height: 150px;
width: 150px;
}
</style>
<script>
var mike = document.getElementById('mike');
mike.onfocus = mike.blur;
mike.onwebkitspeechchange = function(e) {
console.log(e); // SpeechInputEvent
document.getElementById('txt').value = mike.value;
};
</script>
</head>