I want to build a function in Framer (coffeescript) where I can say a specific word as voice input and something happens. For example I say "apple" then a rectangle turns green. If I say "banana" it turns yellow.
So far it works only once and then I have to refresh the prototype in order to record a new word. How can I make it fluent, so I can say more words and always change the colors?
Here is my current code. I use the Google Chrome API for speech recognition, so the prototype itself only works if you open it in the Chrome Browser.
SpeechRecognition = window.SpeechRecognition or
window.webkitSpeechRecognition
recognizer = new SpeechRecognition
recognizer.lang = 'de-DE'
recognizer.continuous = true
recognizer.interimResults = true
recognizer.start()
recognizer.onresult = (event) ->
result = event.results[event.resultIndex]
if result[0].transcript is "Apfel"
rect.backgroundColor = "green"
else if result[0].transcript is "Banane"
rect.backgroundColor = "yellow"
return