$(function(){
$('.input').inputfit();
})
function startDictation() {
if (window.hasOwnProperty('webkitSpeechRecognition')) {
var recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = "en-US";
recognition.start();
recognition.onresult = function(e) {
document.getElementById('transcript').value
= e.results[0][0].transcript;
recognition.stop();
document.getElementById('labnol').submit();
};
recognition.onerror = function(e) {
recognition.stop();
}
}
}
html {
height: 100%;
}
body {
font-family: Helvetica;
overflow-x: hidden;
overflow-y: auto;
}
.b-input-wrapper {
height: 70px;
font-size: 24px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
margin-left: -218px;
margin-top: -30px;
width: 436px;
}
.speak::-webkit-input-placeholder {
color: #4f30c1 !important;
}
.speak::-moz-placeholder {
color: #959595 !important;
}
:-ms-input-placeholder {
color: #959595 !important;
}
input {
width: 250px;
height: 40px;
line-height: 30px;
font-size: 24px;
text-align: left;
}
label {
font-size: 16px;
color: #a0a0a0;
}
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tiny Speech</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="jquery.inputfit.js"></script>
<body>
<div class="b-input-wrapper">
<input type="text" class="input speak" name="q" id="transcript" placeholder="add your word"/>
<img class="mic" onclick="startDictation()" src="https://i.imgur.com/cHidSVu.gif"/>
</div>
</body>
</html>
我正在尝试添加一个jQuery插件,缩小口述的文本以适应输入字段。
到目前为止,只有在字段中键入文本时插件才有效,而不是通过麦克风/ webkitSpeechRecognition指示文本(请参阅下面的脚本网页)。
这是我尝试的调整,但仍然有相同的结果:
$(function(e){
$('.input').inputfit().value
= e.results[0][0].transcript;
})
如何让JavaScript Speech API与jQuery插件一起使用?这不可能吗?