C# – WPF – Voice Control Simple Snake Game

As a beginner in WPF, I am trying to become really better in the subject by changing existing codes and adding some new features in it. This code simply adds a voice control feature of the snake WPF game from here. In general, the original code is kept as it was and I have just added a few lines, to be able to control the snake with voice.

Additionally, I have decided to limit the directions to “left” and “right” only as far as I was yelling a lot while I was testing the code  🙂  Thus, if the snake is going left and you say “right”, the snake would go “up”. Simple as that.

In order to start the game simply say “Left” or “Right”. You may say “Game over” and this would end the game. Other voice commands are not included.

The colors are changed as well 🙂


I have changed a few things in the code, but in general it stays the same. The voice recognition is achieved through  the following:


In order to obtain the classes “Speech RecognitionEngine()”, “GrammerBuilder()” and etc. we need to add the namespaces:

Once, we have them it is really easy to make the code. Two other methods are added. A method for recognizing the speech:


In this method we simply set actions for the three speech commands – “left”, “right” and “game over”. The idea is, as explained to reduce the number of commands.


The process was interesting for me, as far as I am a beginner in WPF and I was really happy to find out that man can do really what he wants. The code here proves it!

The game is somehow “challenging” as far as it has a little slowing between the commands and the action of the snake. Thus, this slowing should be taken into account and the commands should be given 1-2 seconds in advance 🙂

A lot of features could be added, but my initial idea was the voice control only.

Here is the whole game code.

Here you may find the exe file only.

Enjoy the code 🙂


VBA Developer

Tagged with: , , , , , ,