Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 2, 2019 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/005d1e20342251ae635063e5bea888eb to your computer and use it in GitHub Desktop.
Save parzibyte/005d1e20342251ae635063e5bea888eb to your computer and use it in GitHub Desktop.
let sr = new webkitSpeechRecognition();
// El elemento del DOM en donde vamos a colocar lo escuchado
const $texto = document.querySelector("#texto");
sr.onresult = resultado => {
let indiceUltimoElemento = resultado.results.length - 1;
let textoEscuchado = resultado.results[indiceUltimoElemento][0].transcript;
// Concatenamos el HTML
$texto.innerHTML += "<br>" + textoEscuchado;
}
sr.onend = () => {
// Simplemente iniciamos de nuevo ;)
sr.start();
};
// Y lo iniciamos por primera vez ;)
sr.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment