Introduction: Voice Control Video Games Using GlovePIE

About: Computer Science student in the UK

Certain games benefit from an element of voice control. I will be teaching you how to code the popular free game, Team Fortress 2, to respond to your voice. You won't be able to move and shoot guided by your voice alone, but certain actions in the game, for example calling for a medic or taunting lend themselves to voice control.

You will be using GlovePIE, a fantastic free program that uses its own coding language. Don't worry, this coding language is very simple and easy to pick up.

After following this tutorial you should have the skills to code for any other game. I hear that the Arma series also benefits hugely from voice control.

If you like this instructable please vote for it in the Game.Life contest!

Step 1: Downloading and Installing

First you need to install GlovePIE:

1.Go to this website:
2. Click the link that says 'I have 100% Green power'
3. Extract the downloaded zip and run the application called 'PIEfree'

The next couple of steps will be teaching you to do simple coding in GlovePIE. If you just want to download a Team Fortress 2 file, then skip to step 4.

Step 2: Coding

Ok now you just need to code! I'll teach you how to code for Team Fortress 2, then you can apply the same technique to any other game.

1. IF statement
The 'if' statement is arguably the most important. It means that IF the conditions specified are fulfilled, THEN it will carry out some actions. Don't worry if this doesn't make much sense to you right now, it will all become clear eventually. Look at the first picture; this is a typical IF statement. It means that IF it hears you say the word 'medic', it will THEN press 'E'. 

2. 'said'
In GlovePIE, 'said' just means what you say. It will compare your voice to the word 'medic', and if your voice matches the word 'medic', then the IF statement is fulfilled. In other words, this is how GlovePIE hears you. Here's another example:

if said("hello", 5) then...

This would fulfil the IF statement if you say the word 'hello'. The number (5) that comes after the word just means the level of confidence needed to fulfil the statement. 1 is the lowest, and 6 is the highest. If the number was 1, anything that sounds remotely like the word 'hello' would trigger the statement. Note that the word "hello" or "medic" needs to be in speech marks.

3. Press

This just simulates a button press. In this case, the key for a Medic in TF2 is 'E', so it presses E, waits 10 milliseconds then releases E.

4. Keyboard.E

This just tells GlovePIE that you want to simulate a keyboard press. This works for most buttons on the keyboard, e.g. to press 'Alt' you would say: press keyboard.Alt. However, for the number keys (above the letters) you have to say: 'press key.1' or 'press key.5'.
It works for the mouse too, to left click you could type: mouse.LeftButton

5. End if
This tells GlovePIE that once it has pressed and released 'E', it has finished. If you have no 'end if', all the code underneath would be triggered whenever you say 'Medic'

Any questions so far? Comment below


Step 3: More Coding

Ok this is a tad more complex. In Team Fortress 2 (or TF2, for short), if you press 'X', then '2', your character shouts 'Spy!'. It is easy to make this voice controlled. Look at the code in the picture. It is exactly the same as the medic code, just with a few more lines for the '2' key. This presses x, releases x, presses 2, then releases 2. Actually quite simple.

If you need to press two keys at the same time, just do something like this:

If said("spy", 5) then 
   press keyboard.x
   press keyboard,2
   wait 10 ms
   release keyboard.x
   release keyboard.2
end if

Ok now I want you to code an IF statement for calling for help in TF2. In game, you have to press 'C', then '1' to call for help. Code it so that if you say "help" the in game character shouts 'help'. Look at the next step to see if you got it right.

Step 4: 'Help'

If your code looks like this, then well done!!

Don't forget to save your file. Here's one more finishing touch:
Put this in to your code to make it so that when you say 'hide', the glovepie window disappears, and when you say 'show', the glovepie windows appears.

if said("hide", 5) or said("hide glove pie", 5) then
end if

if said("show", 5) or said("show glove pie", 5) then
end if

Notice the 'OR' statement - this means that GlovePIE will recognise both "hide" and "hide GlovePIE". 

Here's my file download for people who don't want to bother learning to code:

Ok now go and apply this code to other games! I hear that this works particularly well for the Arma series. If you have any creative uses for GlovePIE then I'd love to hear them in the comments! 

If you want a bit more complex code, and have GlovePIE speak back to you then check out this instructable:

And if you want to be able to control GlovePIE from your phone or tablet check out this instructable:

If you enjoyed this instructable vote for it in the Game.Life contest!!

Game.Life 4 Contest

Participated in the
Game.Life 4 Contest