Last active
December 7, 2018 14:35
-
-
Save rmdias/24f26473f4453d79b846fd5d3be4a645 to your computer and use it in GitHub Desktop.
Speech Recognition
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
const SpeechRecognition = webkitSpeechRecognition; | |
const SpeechGrammarList = webkitSpeechGrammarList; | |
const SpeechRecognitionEvent = webkitSpeechRecognitionEvent; | |
const recognition = new SpeechRecognition(); | |
const speechRecognitionList = new SpeechGrammarList(); | |
recognition.grammars = speechRecognitionList; | |
recognition.lang = 'pl-PL'; | |
recognition.continuous = true; | |
recognition.interimResults = true; | |
recognition.maxAlternatives = 1; | |
recognition.start(); | |
recognition.onresult = function(event) { | |
const last = Object.keys(event.results).length - 1; | |
const transcript = event.results[last][0].transcript; | |
handleSnoopRest(transcript); | |
} | |
function handleSnoopRest(transcript) { | |
const hasWakeUpCommand = transcript.includes('obudź') || transcript.includes('zbudzić'); | |
const hasSleepCommand = transcript.includes('sen') || transcript.includes('spać') || transcript.includes('śpij'); | |
if (hasSleepCommand) { | |
snoopSleepingAnimation(); | |
} | |
if (hasWakeUpCommand){ | |
snoopWakeupAnimation(); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment