![]() |
VOOZH | about |
Speech recognition is the process of turning spoken words into text. It is a key part of any voice assistant. In Python the SpeechRecognition module helps us do this by capturing audio and converting it to text. In this guide we’ll create a basic voice assistant using Python.
Run the following command in the command prompt to install all necessary libraries:
!pip install SpeechRecognition pyttsx3 wikipedia pyjokes
After installing we import all the libraries we need like pyttsx3 for speaking out loud, datetime to fetch the current time, wikipedia to search and fetch content and many more.
We create a function called speak that accepts a string as input. This function prints and speaks input.
We then create a wish_user() function to greet the user based on the current time like:
This makes the assistant feel more natural and friendly. It also introduces itself and asks how it can help.
Normally you would talk to the assistant using your microphone. But since Google Colab doesn’t support voice input we use this by creating a list of commands in code. These are just sample phrases like:
"what is python wikipedia""open youtube""what's the time""exit"This list helps us test how assistant will respond without needing a real voice input.
The run_assistant loops through the list of commands and checks what each command is asking for.
Finally we call the run_assistant() function to start everything. It first greets the user then goes through each command and performs the correct action.
Output:
This assistant can perform different tasks based on voice commands, such as telling the time, opening websites, sending emails, telling jokes, search on Wikipedia, open websites and many more.
You can download the full code from here