javascript - 用 JavaScript 覆盖文本框语音到文本
问题描述
通过网络语音 API,我使用 html 和 javascript 将语音转换为文本。每次说话时如何覆盖文本框?对于当前时刻,每次我说新的下一个删除上一个。如何在说话后保留文本框中的所有文本而不删除以前的文本?
var btnSpeechEnfSig = document.getElementById('btnSpeechEnfSig');
btnSpeechEnfSig.onclick = function() {
var output = document.getElementById("enf_signopsis");
// get action element reference
var action = document.getElementById("actionSpeechEnfSig");
runSpeechRecognition(output,action);
}
function runSpeechRecognition(output,action) {
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var recognition = new SpeechRecognition();
// This runs when the speech recognition service starts
recognition.onstart = function() {
action.innerHTML = "<small>escuchando, habla...</small>";
};
recognition.onspeechend = function() {
action.innerHTML = "<small>grabación terminó...</small>";
recognition.stop();
}
// This runs when the speech recognition service returns result
recognition.onresult = function(event) {
var transcript = event.results[0][0].transcript;
output.value += transcript;
}
};
<button type="button" id="btnSpeechEnfSig" ><i class="fa fa-microphone""></i></button>
<span id="actionSpeechEnfSig"></span>
<textarea rows="6" id="enf_signopsis" ></textarea>
解决方案
使用output.value += transcript;
.
推荐阅读
- javascript - 如何跟踪 JavaScript 执行性能?
- java - Solr 并停止
- f# - 针对 SQL 数据库的 F# 执行顺序
- c++ - list::empty() 多线程行为?
- javascript - onblur="function(this)" 不适用于多个动态创建的文本框
- javascript - JavaScript:使用动态数据显示交互式地图
- mysql - 了解 MySQL 查询优化器
- c# - 由于奇怪的编译错误 CS0234,Razor 无法渲染视图
- reactjs - 使用 `@emotion/core` 和最新版本的 React 时,CodeSandbox 中的“React.createContext 不是函数”
- powershell - 日期转换 yyyymmddhhmm+000