Virtual Assistant: Fun Coding

Code for yourself.

sanchit sharma
TEK Society
4 min readDec 4, 2020

--

source: https://insights.dice.com/

Having your own Virtual assistant is really cool thing. But you will find it more interesting if you indulge in the process of making your own Virtual Assistant (or AI Assistant) with help of python libraries.

What’s Virtual Assistant?

It’s an application program that understands natural language voice commands and completes tasks for the user.

Today, we will be making a Virtual Assistant called “Steffi” with help of some great python libraries(Install the packages before starting the project).

This program will do specific tasks once it is activated with voice instructions.

Some tasks done by Steffi

  1. Wishes you after running the program.
  2. Asks your name.
  3. Search Wikipedia
  4. Play music

So on...

Start Coding with Importing the libraries:

  • wikipedia: It is used to fetch a variety of information from the Wikipedia website
  • speech-recognition: It allows us to convert audio into text.
  • pyttsx3: It is a text-to-speech conversion.
  • webbrowser: It provides a high-level interface that allows displaying Web-based documents to users.
  • OS: The OS module in Python provides functions for interacting with the operating system.

Next part of the program that creates an engine which is used in speak( ) function,

SAPI5: Microsoft Speech API (SAPI5) is the technology for voice recognition and synthesis provided by Microsoft

In the third line, you can change the index to change voice

voice[1].id = For Female voice
voice[0].id = For Male voice

Functions to perform tasks

These functions are like the core part of your virtual assistant.

  • To speak, Text to Speech
  • Wanna know the Day: This function is for telling the day of the week
  • Wish me: Steffi is gonna wish you
  • Let Steffi know who are you…Okay
  • Take command: It takes microphone input from the user and returns the string output.

r.pause_threshold = 1 It refers to the amount of time gap after which the audio is supposed to be complete.
audio=r.listen(source) Digital data of whatsoever has been spoken will be stored in the audio.

  • Main function: This Function will clean any command before execution of this python file.

Here comes the fun part. You can code here whatever you want that your Digital Assistant do for you with the voice instruction.

Continue...

“Steffi” is a virtual assistant for basic works. However, you can enhance its functionality according to your needs.

Enjoy your personal Virtual Assistant Steffi.. Or name yours What you want!!

Any Suggestion, How we can enhance the Functionality ??

Comment below...

--

--