Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created March 31, 2024 10:21
Show Gist options
  • Save KaushikShresth07/6cbeb81516bf561d7ee5e82e208e071b to your computer and use it in GitHub Desktop.
Save KaushikShresth07/6cbeb81516bf561d7ee5e82e208e071b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Speech Recognition</title>
</head>
<body>
<button id = "start" onclick="startRecognition()">Start Recognition</button>
<button id = "end" onclick="stopRecognition()">Stop Recognition</button>
<p id = "output"></p>
<script>
const output = document.getElementById('output');
let recognition;
function startRecognition() {
recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.lang = 'en-US';
recognition.continuous = true;
recognition.onresult = function(event) {
const transcript = event.results[event.results.length - 1][0].transcript;
output.textContent += transcript;
};
recognition.onend = function() {
recognition.start();
};
recognition.start();
}
function stopRecognition() {
recognition.stop();
output.innerHTML = ""
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment