Playing Space Invaders With Your Own Voice

Photo by Andre Hunter

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?

So let’s do a simple experiment with a Space Invaders written in Javascript.

Final result (Kind of)

After some walkarounds I made a requirement list in order to reach my target:

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:

https://medium.com/media/9f4047fe8a78c6d53ad7c6c0ed3a40ed/href

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.

https://medium.com/media/c9034aef3b0d3ec0c9ab777bbfe56c17/href

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.

https://medium.com/media/fec1eafba59f0d3bfb095d123efc830a/href

And the final and editable result are:

Space Invaders – Woice Annotated code

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 :).


Playing Space Invaders With Your Own Voice was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: