Heya! We use cookies

Codesphere uses cookies to understand your preferences and make sure you have the best experience on our site. By using Codesphere, you accept our use of cookies.

Accept Cookies

Manage Consent Preferences

Choose what cookies you allow us to use. You can read more about our Cookie Policy.
Strictly Necessary Cookies
Required

These cookies allow core website functionalities such as user login. The website cannot be used properly without strictly necessary cookies.

Performance Cookies

These cookies are used by third-party analytics tools to capture user behavior on our website to understand user interactions and make product improvements.

Marketing Cookies

These cookies are used by third-party companies to remember visitor behavior across the website to deliver relevant promotions and other content on external platforms.

Confirm

Creating Your Own Voice Assistant in Python

04.07.2022

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.


How the Voice Assistant Works

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.


Setup

In a new python project, first install the speech recognition library with:

pip install SpeechRecognition

And install the TTS library with:

pip install pyttsx3


The Code

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

Building More

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!