Let’s be honest with ourselves, at some point in our lives we wanted our own Jarvis. There’s something incredibly awesome about having a personal voice assistant to be able to give us information, manage our schedules, and just help us out with our day to day lives.
In this article, we’ll build a foundation with python that you can use to build your own personal voice assistant.
The foundation of our program will be a speech recognition library and a Text to speech library(TTS) which will allow us to communicate with our script purely through audio.
The script will run on a loop of:
- Waiting for a command from the user
- Understanding and fulfilling a command
We’ll add some basic examples to do some small talk, tell the time, open apps and a few other things. This foundation can very easily be augmented to add whatever functionality you might want from your assistant. If you can do it in python, you can make the bot do it.
In a new python project, first install the speech recognition library with:
pip install SpeechRecognition
And install the TTS library with:
pip install pyttsx3
In a python file, we’re then going to:
- Load in our imports
- Configure the text to speech
- Define our speech function
The bot above can fulfill the following commands:
- Tell the time
- Give a random number
- Open and Close Slack
Whatever tasks you want your assistant to complete, you can now simply add another conditional to the list!
Of course, you can add a lot more complexity:
- Power the assistant w/ Conversational AI via Rasa
- Play music with the Spotify API
- Pull information from wikipedia via Web Scraping
That’s all for today!
Got any questions? Let us know down below.
As always, happy coding from your friends at Codesphere, the swiss army knife that every development team needs!