Created
October 5, 2022 20:20
-
-
Save aibolik/1d31a8d54327ee97ba021cfb6d72d183 to your computer and use it in GitHub Desktop.
Example of SpeechRecognition API usage
This file contains 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
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