<body>
<h1>Welcome To World Of Coders</h1>
<button class="button-three" id="btn" onclick="recognition.start()">
Speech To text
</button>
<div id="result" class="container">
<p>Text is show here</p>
</div>
<button class="button-three" onclick="copyDivToClipboard()">
Copy the text
</button>
</body>
<body>
<h1>Welcome To World Of Coders</h1>
<button class="button-three" id="btn" onclick="recognition.start()">
Speech To text
</button>
<div id="result" class="container">
<p>Text is show here</p>
</div>
<button class="button-three" onclick="copyDivToClipboard()">
Copy the text
</button>
</body>
There is all the Html Code for the Speech To Text. Now, you can see output without Css and JavaScript. then we write Css to style our project and then use JavaScript Code for Speech To Text Functionality in Project.
window.getSelection().removeAllRanges(); // clear current selection
window.getSelection().addRange(range); // to select text
document.execCommand("copy");
window.getSelection().removeAllRanges();// to deselect
alert("Copied the text:")
}
const btn = document.getElementById("btn");
const results = document.getElementById("result");
const speechRecognition = window.speechRecognition || window.webkitSpeechRecognition;
const recognition = new speechRecognition();
recognition.onstart = function(){
console.log("you can speek now");
}
recognition.onresult = function(event){
var text = event.results[0][0].transcript;
console.log(text);
document.getElementById("result").innerHTML = text;
}
function copyDivToClipboard() {
var range = document.createRange();
range.selectNode(document.getElementById("result"));
window.getSelection().removeAllRanges(); // clear current selection
window.getSelection().addRange(range); // to select text
document.execCommand("copy");
window.getSelection().removeAllRanges();// to deselect
alert("Copied the text:")
}
const btn = document.getElementById("btn");
const results = document.getElementById("result");
const speechRecognition = window.speechRecognition || window.webkitSpeechRecognition;
const recognition = new speechRecognition();
recognition.onstart = function(){
console.log("you can speek now");
}
recognition.onresult = function(event){
var text = event.results[0][0].transcript;
console.log(text);
document.getElementById("result").innerHTML = text;
}
function copyDivToClipboard() {
var range = document.createRange();
range.selectNode(document.getElementById("result"));
window.getSelection().removeAllRanges(); // clear current selection
window.getSelection().addRange(range); // to select text
document.execCommand("copy");
window.getSelection().removeAllRanges();// to deselect
alert("Copied the text:")
}
Final Output Of Speech To Text Using JavaScript
Now we have completed our Speech To Text. Here is our updated output with Html, Css, and JavaScript. Hope you like Speech To Text. you can see the output video and project screenshots. See our other blogs and gain knowledge in front-end development.
In this post, we learn how to Create a Speech To Text Using HTML, CSS, and JavaScript. If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.