Python

Lock PC with voice command using Python

Lock PC with voice command is a tutorial that will explain to you how to lock windows PC with a voice command. Voice recognition is going to be a huge hit in the future that will make the humans interact with the machines very easily. Though this technology is still available online but not free of cost at all. There are few companies that provide API for Speech to Text but you have to pay if you want to use it for a commercial purpose. Though you can use for trial purposes.

In this tutorial, I’ll show you how to Lock PC with voice command using Python and the Google Speech API. But first of all, we need to setup environment to write and test the code.

Setup Environment

Install Python

You can download the Python installer from here. Install the setup after download.

Install SpeechRecognition Python module 

You can install any Python module using pip command. Open command prompt and execute this command to install the SpeechRecognition module.

Sample Source Code

Finally, this is the Python source that will Lock the PC with voice command. Also, the source code contains the explanation. If you need further some help or have some query, you can also write in the comment box.

Execute the command through the command line or clicking on the file. You can execute the script using command line using the following command:

While the script is in execution, speak this command i.e. “lock my PC” if you use the same keyword as mentioned in the code above. Make sure you are connected to the internet and your PC mic is working properly. Your PC will be locked once the script recognized your voice. There might be a delay of few seconds depending on the internet speed and response of the Google Speech API.

This ends the tutorial of Lock PC with voice command. Hope you like the tutorial.

Please share this post and spread the knowledge.

About the author

Sujeet Kr Singh