Created
June 25, 2022 23:57
-
-
Save brito/112dc5d3ac0a1bdc53ac889f0c1cd698 to your computer and use it in GitHub Desktop.
Minimal webkit speech recognition and synthesis demo
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
// Voice Driven Web Apps | |
//developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api | |
with (new webkitSpeechRecognition) | |
continuous = | |
interimResults = | |
true, | |
onstart = | |
onerror = | |
onend = | |
console.info, | |
voice = speechSynthesis.getVoices()[50], | |
onresult = | |
e => [...e.results] | |
.map(result => { | |
with(result[0]) | |
if (result.isFinal) | |
speechSynthesis.speak(new SpeechSynthesisUtterance(transcript)), | |
stop() | |
else | |
(confidence > .618 ? console.warn : console.debug)(result[0]) | |
}), | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment