39

Playing Space Invaders With Your Own Voice

 5 years ago
source link: https://www.tuicool.com/articles/hit/Ej6n6nM
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
mMjmEfe.jpg!webYV773yQ.jpg!web
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.

e2Abya6.jpgjIr6vym.gif
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:

Handler Definition

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.

Instantiation

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.

Recognition Binding

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK