Created
December 11, 2020 15:41
-
-
Save radheymkumar/466b6ccbd687172a1100aa620009c27c to your computer and use it in GitHub Desktop.
Voice open page
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
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; | |
const recognition = new SpeechRecognition(); | |
recognition.interimResults = true; | |
recognition.addEventListener('result', e => { | |
transcript = Array.from(e.results).map(result => result[0]).map(result => result.transcript).join(''); | |
const statement = e.results[0][0].transcript; | |
console.log(statement); | |
if (statement === "voice admin new page") { | |
window.location.href = "/node/add/page"; | |
} else if (statement === "voice admin new article") { | |
window.location.href = "/node/add/article"; | |
} else if (statement === "voice admin log out") { | |
window.location.href = "/user/logout"; | |
} else if (statement === "voice admin go home") { | |
window.location.href = "/en"; | |
} | |
}); | |
// When we stop talking, start the process again, so it'll record when we start | |
// talking again. | |
recognition.addEventListener('end', recognition.start); | |
recognition.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment