Playing Space Invaders With Your Own Voice
After some time testing voice games in my Alexa device, one question came to my mind…
Why not try to convert a classic game control system to a Voice User Inteface?
After some walkarounds I made a requirement list in order to reach my target:
- Speech Recognition
- Speech Synthesis
- An NLU or set of hardcode rules to match my utterances to intents
- Implementation of the web reactions to these intents
Well, once I had more or less clear what I was looking for, I use the second engineer lesson: don’t reinvent the wheel. So, once again I whispered something to Google and it led me to something called Woice.
Once I went through the tutorial for creating a new application, I charged the SDK script on my HTML and draw a few lines of code over the space invaders control system.
These lines can be explained in three concepts: Handler, Instance and Speech Recognition Trigger.
The first concept is the Handler which is composed by 2 functions: canHandle, which dictates if the code of the second function handle should be executed or not.
I know, it’s easier if we have some tangible:
The code above goes as simple as this: when we match the intent ‘moveRight’ in the Dialogflow agent (this is Woice’s supported NLU), we trigger GlobalActionState.RIGHT = true.
The second concept is the instance, once we have defined our handlers we are going to build a Woice instance with these.
And the last one, we are going to attach a Speech Recognition Trigger. In this case, we associate this event to the control+B keyboard combination.
And the final and editable result are:
It’s definitely not the best use case (gaming requires real-time action, so it’s not really suited for voice) but, in the other hand, I played more time that I would like to admit.
If you have any question, review, or simply a project you want to share with me I’m glad to hear from you :).