Created
March 10, 2023 18:42
-
-
Save andreescocard/b31e173211b1d301652af7e958d152ce to your computer and use it in GitHub Desktop.
speech2text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple Command Voice</title> | |
</head> | |
<body> | |
<p id="output"></p> | |
<button id="start">Click and say something!</button> | |
<script> | |
(() => { | |
const startBtn = document.querySelector('#start'); | |
const output = document.querySelector('#output'); | |
function start() { | |
const recognition = new webkitSpeechRecognition(); | |
recognition.interimResults = true; | |
recognition.lang = "pt-BR"; | |
recognition.continuous = true; | |
recognition.start(); | |
// This event happens when you talk in the microphone | |
recognition.onresult = function(event) { | |
for (let i = event.resultIndex; i < event.results.length; i++) { | |
if (event.results[i].isFinal) { | |
// Here you can get the string of what you told | |
const content = event.results[i][0].transcript.trim(); | |
output.textContent = content; | |
} | |
} | |
}; | |
}; | |
startBtn.addEventListener('click', () => start()); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment