Coders Packet

AI Desktop Voice Assistant and Calculator Using Python

By Diwesh Prashar

Jarvis AI Desktop Voice Assistant Using Python. You can also calculate number by giving voice command.

What can this A.I. assistant do for you?

  • It opens notepad by giving voice command.
  • It also work as a calculator by giving voice command.
  • It also give you tempreture update and exact time.
  • It is capable of opening websites like Google, Youtube, etc., in a web browser.
  • Most unique function "activate how to do mode". It can return Google search of anything you want to know. (eg:- suppose you give a command how to make a cake, then it gives step by step process of making it ).

Defining Wish me Function :

Now, we will make a wishme() function that will make our J.A.R.V.I.S. wish or greet the user according to the time of computer or pc. To provide current or live time to A.I., we need to import a module called datetime. Import this module 

The next most important thing for our A.I. assistant is that it should take command with the help of the microphone of the user's system. So, now we will make a takeCommand() function. With the help of the takeCommand() function, our A.I. assistant will return a string output by taking microphone input from the user.

 Before defining the takeCommand() function, we need to install a module called speechRecognition. Install this module by: pip install speechRecognition 

After wishme() function there is take command() which take your voice as a input and convert in text as a string.

you have to use Microphone as a input to take command.

After all that now we have to make main method where we describe function which we want to give as a input to work.

In main method firstly we have to give query like open notepad. So, if it is in query then execute below code. 

then you have to define path of your notepad.

Same as like this for other function like open youtube or Google .Yes, here important thing is that you need to import webbrowser module.

Then we put 'Calculation' in query. For that we need to import operator module to do such calculation.

After that we define two function

get_operator_fn - it consist all the operation that we want to operate like '+','-' etc:
eval_binary_expr - it is necessary because you are giving voice command and system take it into string form so, there it operate all the action that it takes. It convert it into strings and save it my_string variables.
After that if you know the weather forecasts just give temprature in query then you have to import two modules 1) import requests 2) BeautifulSoup
these two modules help to find tempreture. Requests module help to search tempreture of given location and BeautifulSoup is work for find the data and print it.
After that there is a function called "Activate How to do mode"
Here you need to install one module called pywikihow it also return google search in table method.
eg:- you give a command of how to make a cake then it gives following steps wheather it is two steps or twenty. It gives all step to do following so.
and such function is better to be under try or exception because if you give wrong command then it print exception result.


What is pyttsx3?
  • A python library that will help us to convert text to speech. In short, it is a text-to-speech library.
  • It works offline, and it is compatible with Python 2 as well as Python 3.

Also import OS module it helps and allow us to find any thing in your desktop like you want to open notepad then it helps to find location of that file.



Download Complete Code


No comments yet