A voice-based unlock system for our computer will be the application that will take our voice as input and process that voice converts it into a text-based instruction for our computer and then perform an action based on that instruction. This process uses The State-of-the-art process in a speech to text, Natural Language Understanding, and Deep Learning in the text to speech.
The first step to build a voice-based application in our application is to listen to the user’s voice constantly and then transcribe that voice into text-based instruction.
This is difficult to create a voice to text transcription engine with the higher accuracy as we need to train our data model for that also there are a lot of industry leaders are available as Google, Microsoft, Apple, and some others are providing their API based services which can be easily integrated with the applications. Google also offers voice action which is an API-based service to perform an action within the app seamlessly using voice.
If you are interested to develop your own speech-to-text application, please go through it. Now for building your own python based application please do follow these steps :
1. Import libraries
- Library ctypes is a foreign function library for Python. Which provides C compatible data types and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.
- Speech Recognition is an important feature in several applications used such as home automation, artificial intelligence, etc.
2. Audio by the Microphone
Now obtain the audio from your microphone using the Recognizer() function of python’s speech_recognition module. In this way, we have captured the voice command from our system.
3. Check command
Now the time is to use the Google speech recognition engine note this point instead of using this API you can use your own voice recognition system. And you need to handle some exceptions via your code for errors coming from the Google engine.
4. Validate Command
Now the time is to match and compare the pattern of the voice command. And load and execute the command to lock the PC. This Function for locking the pc is available in the default library (user32.dll) of windows. And you can use Linux also but the command will be different for this operation and the default library will be available on (cell.user32) as well.
Below is the Implementation.
Here, we will form a function (method) that repeatedly calls itself until the required commands.
- If the command is to lock pc then it locks pc.
- If the command is a stop the program then it stops the program.
- Otherwise, It says not a codded command and runs again.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.