Skip to content

Instantly share code, notes, and snippets.

@aibolik
Created October 5, 2022 20:20
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 aibolik/1d31a8d54327ee97ba021cfb6d72d183 to your computer and use it in GitHub Desktop.
Save aibolik/1d31a8d54327ee97ba021cfb6d72d183 to your computer and use it in GitHub Desktop.
Example of SpeechRecognition API usage
let recognition = new window.SpeechRecognition();
recognition.interimResults = true;
recognition.addEventListener('result', e => {
const transcript = Array.from(e.results)
.map(result => result[0])
.map(result => result.transcript)
.join('');
if (e.results[0].isFinal) {
// this is the final version, feel free to do whatever you need with transcript/text
}
});
recognition.addEventListener('end', e => {
// recognition finished, you can stop recording here
});
// call this one to start recording
recognition.start();
// call this to stop recording
recognition.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment