Project 1: Iron Man Jarvis AI Desktop Voice Assistant | Python Tutorials For Absolute Beginners #120

Have you ever wondered how cool it would be to have your own A.I. assistant? Imagine how easier it would be to send emails without typing a single word, doing wikipedia searches without opening web browsers, and performing many other daily tasks like playing music with the help of a single voice command.

In this tutorial, I will teach you how you can make your personal A.I. assistant using Python. 

 

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

  • It can send emails for you.
  • It can play music for you.
  • It can do Wikipedia searches for you.
  • It is capable of opening websites like Google, Youtube, etc., in a web browser.
  • It is capable of opening your code editor or IDE with a single voice command.

Enough talk! Let's start building our own J.A.R.V.I.S.

 

10:08 – Starting VS Code

I am going to use the VS Code IDE in this video. Feel free to use any other IDE you are comfortable d with. Start a new project and make a file called jarvis.py.

 

10:54 – Defining Speak Function

The and first and foremost thing for an A.I. assistant is that it should be able to speak. To make our J.A.R.V.I.S. talk, we will make a function called speak(). This function will take audio as an argument, and then, it will pronounce it.

 

def speak(audio):
       pass      #For now, we will write the conditions later.

Now, the next thing we need is audio. We must supply audio so that we can pronounce it using the speak() function we made. We are going to install a module called pyttsx3.

 

What is pyttsx3?

  • A python library which 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 the Python 3.

Installation:

pip install pyttsx3

In case you receive such errors: 

  • No module named win32com.client
  • No module named win32
  • No module named win32api

Then, install pypiwin32:

pip install pypiwin32.

After successfully installing pyttsx3, import this module in your program.

 

Usage:

import pyttsx3

engine = pyttsx3.init('sapi5')

voices= engine.getProperty('voices') #getting details of current voice

engine.setProperty('voice', voice[0].id)

 

What is sapi5?

  • Speech API developed by Microsoft.
  • Helps in synthesis and recognition of voice

 

What Is VoiceId?

  • Voice id helps us to select different voices.
  • voice[0].id = Male voice 
  • voice[1].id = Female voice

 

Writing Our speak() Function?

We made a function called speak() at the starting of this tutorial. Now, we will write our speak() function so that it can convert our text to speech.

 

def speak(audio):

engine.say(audio) 

engine.runAndWait() #Without this command, speech will not be audible to us.

 

Creating Our main() function: 

 

Now, we will create a main() function, and inside this main() Function, we will call our speak function.

 

Code:

if __name__=="__main__" :

speak("Code With Harry")

 

Whatever you will write inside this speak() function will be converted into speech. Congratulations! With this, our J.A.R.V.I.S. has its own voice, and it is ready to speak.

 

15:25 - Defining Wish me Function

 

Now, we are going to 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 to your program, by:

 

import datetime

 

Now, let's start defining our wishme() function:

 

def wishme():

hour = int(datetime.datetime.now().hour)

 

Here, we have stored the integer value of the current hour or time into a variable named hour. Now, we will use this hour value inside an if-else loop.

 

def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")   

    else:
        speak("Good Evening!")  

    speak("I am Jarvis Sir. Please tell me how may I help you")   

 

 

18:27 – Defining Take command Function 

 

The next most important thing for our A.I. assistant is that it should be able to 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 be able to 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 successfully installing this module, import this module into the program by writing an import statement.

import speechRecognition as sr

 

 

Let's start coding our takeCommand() function.

def takeCommand():
    #It takes microphone input from the user and returns string output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

 

We have successfully created our takeCommand() function. Now we are going to add a try and except block to our program to handle errors effectively.

  try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in') #Using google for voice recognition.
        print(f"User said: {query}\n")  #User query will be printed.

    except Exception as e:
        # print(e)    
        print("Say that again please...")   #Say that again will be printed in case of improper voice 
        return "None" #None string will be returned
    return query

 

27:30 – Coding logic of Jarvis

 

Now, we will develop logics for different commands such as Wikipedia searches, playing music, etc.

 

28:04 – Defining Task 1: To search something on Wikipedia 

 

To do Wikipedia searches, we need to install and import the Wikipedia module into our program. 

 

Installing wikipedia module:

pip install wikipedia

 

After successfully installing wikipedia module, import the wikipedia module into the program by writing an import statement.

if __name__ == "__main__":
    wishMe()
    while True:
    # if 1:
        query = takeCommand().lower() #Converting user query into lower case

        # Logic for executing tasks based on query
        if 'wikipedia' in query:  #if wikipedia found in the query then this block will be executed
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2) 
            speak("According to Wikipedia")
            print(results)
            speak(results)

 

In the above code, we have used an if statement to check whether Wikipedia is in the search query of the user or not. If Wikipedia is found in the user's search query, then two sentences from the summary of the Wikipedia page will be converted to speech with the help of speak function.

 

31:24 – Defining Task 2: To open YouTube site in a web-browser

 

To open any website, we need to import a module called webbrowser.

It is an in-built module, and we do not need to install it with pip statement, we can directly import it into our program by writing an import statement.

 

Code: 

     elif 'open youtube' in query:
            webbrowser.open("youtube.com")

Here, we are using the elif loop to check whether the Youtube is in the query of the user or not. Let' suppose, the user gives command as "J.A.R.V.I.S., open youtube."

So, open youtube will be in the user's query, and the elif condition will be true.

 

32:34 – Defining Task 3: To open Google site in a web-browser

elif 'open google' in query:
            webbrowser.open("google.com")

We are opening Google in a web-browser by applying the same logic that we used while opening Youtube. 

 

33:37 – Defining Task 4: To play music 

 

To play music, we need to import a module called os. Import this module directly with an import statement.

elif 'play music' in query:
            music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2'
            songs = os.listdir(music_dir)
            print(songs)    
            os.startfile(os.path.join(music_dir, songs[0]))

In the above code, we first opened our music directory and then listed all the songs present in the directory with the help of the os module.

With the help of os.starfile, you can play any song of your choice. I am playing the first song in the directory. However, you can also play a random song with the help of a random module. Every time you command to play music, J.A.R.V.I.S. will play any random song from the song directory.

 

36:58 – Defining Task 5: To know the current time

  elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

In the above, code with are using datetime() function and storing the current or live of the system into a variable called strTime.

After storing the time in strTime, we are passing this variable as an argument in speak function. Now, the time string will be converted into the speech.

 

38:45 – Defining Task 6: To open the VS Code Program

 elif 'open code' in query:
            codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
            os.startfile(codePath)

 

To open the VS Code or any other application, we need the code path of the application.

 

Steps of getting the code path of the application:

Step 1: Open the file location.

Step 2: Right-click on the application and click on properties.

Step 3: Copy the target from the target section.

 

After copying the target of the application, save the target into a variable. Here, I am saving the target into a variable called codePath, and then we are using the os module to open the application.

 

41:05 – Defining Task 7: To send Email

 

To send an email, we need to import a module called smtplib.

 

What is smtplib?

  • Simple Mail Transfer Protocol (SMTP) is a protocol that allows us to send emails and to route emails between mail servers.

 

An instance method called sendmail is present in the SMTP module. This instance method allows us to send an email. 

It takes 3 parameters:

  • The sender: Email address of the sender.
  • The receiver:T Email of the receiver.
  • The message: A string message which needs to be sent to one or more than one recipient.

 

44:03 – Defining Send email function :

Now, we will create a sendEmail() function, which will help us to send emails to one or more than one recipients.

def sendEmail(to, content):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login('youremail@gmail.com', 'your-password')
    server.sendmail('youremail@gmail.com', to, content)
    server.close()

In the above code, we are using the SMTP module, which we have already discussed above.

Note: Do not forget to 'enable the less secure apps' feature in your Gmail account. Otherwise, the sendEmail function will not work properly.

 

Calling sendEmail() function inside the main() function:    

 elif 'email to harry' in query:
            try:
                speak("What should I say?")
                content = takeCommand()
                to = "harryyourEmail@gmail.com"    
                sendEmail(to, content)
                speak("Email has been sent!")
            except Exception as e:
                print(e)
                speak("Sorry my friend harry bhai. I am not able to send this email")    

We are using the try and except block to handle any possible error that can occur while sending emails.

 

 

51:26 – Recapitulate

What have we done so far? 

  1. First of all, we have created a wishme() function that gives the functionality of greeting according to the system time to our A.I.
  2. After wishme() function, we have created a takeCommand() function, which helps our A.I to take command from the user. This function is also responsible for returning the user's query in a string format.
  3. We developed the code logic for opening different websites like google, youtube, and stack overflow.
  4. Developed code logic for opening VS Code or any other application.
  5. At last, we added functionality to send emails.

 

56:13 – Is it an A.I.?

A lot of people will argue that the virtual assistant that we have created is not an A.I, but it is the output of the bunch of the statement. But, if we look at the very basic level, the sole purpose of A.I is to develop machines that can perform human tasks with the same effectiveness or even more effectively than humans.

It is a fact that our virtual assistant is not a very good example of A.I., but it is an A.I. !

 

58:30 – The E.N.D.

With this, you have successfully made your very first virtual assistant. Explore and try to add other functionalities to J.A.R.V.I.S. I hope you all have liked this blog.

Please do like, share, and comment if you have any queries. It would be my pleasure to help you.

 

 

 

 

 

 

 

Code as described/written in the video

import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].id)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")   

    else:
        speak("Good Evening!")  

    speak("I am Jarvis Sir. Please tell me how may I help you")       

def takeCommand():
    #It takes microphone input from the user and returns string output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        print(f"User said: {query}\n")

    except Exception as e:
        # print(e)    
        print("Say that again please...")  
        return "None"
    return query

def sendEmail(to, content):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login('youremail@gmail.com', 'your-password')
    server.sendmail('youremail@gmail.com', to, content)
    server.close()

if __name__ == "__main__":
    wishMe()
    while True:
    # if 1:
        query = takeCommand().lower()

        # Logic for executing tasks based on query
        if 'wikipedia' in query:
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            print(results)
            speak(results)

        elif 'open youtube' in query:
            webbrowser.open("youtube.com")

        elif 'open google' in query:
            webbrowser.open("google.com")

        elif 'open stackoverflow' in query:
            webbrowser.open("stackoverflow.com")   


        elif 'play music' in query:
            music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2'
            songs = os.listdir(music_dir)
            print(songs)    
            os.startfile(os.path.join(music_dir, songs[0]))

        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

        elif 'open code' in query:
            codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
            os.startfile(codePath)

        elif 'email to harry' in query:
            try:
                speak("What should I say?")
                content = takeCommand()
                to = "harryyourEmail@gmail.com"    
                sendEmail(to, content)
                speak("Email has been sent!")
            except Exception as e:
                print(e)
                speak("Sorry my friend harry bhai. I am not able to send this email")    

Comments(67)

sikendra1234 11 months ago
thanks a lot harry bhai for such an awesome vedio. please make some more vedio related to project. please a series of vedio on AI
harry 11 months ago
Sure brother. I will surely add more videos soon!
kartik100 11 months ago
Could not find PyAudio; check installation Sir, I am facing this error, please help.
kartik100 11 months ago
how can i change speeking language to hindi
utkarsh 10 months, 1 week ago
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio This should help you :)
nishankt139 10 months, 3 weeks ago
I m facing attribute error: __enter__. What should I do ????
Mihir787 10 months, 3 weeks ago
Harry bhai I got error same like I mentioned here https://stackoverflow.com/questions/55984129/attributeerror-could-not-find-pyaudio-check-installation-cant-use-speech-re After that I installed visual studio c++ build tools but then after also error occurred
Kabir12 10 months, 2 weeks ago
Hi Harry I m not able to give commands to the project it notify me with "unanticipated host error"
Sankalp@1234 10 months, 1 week ago
sir after installing pyaudio it gives error "Please build and install the PortAudio Python bindings first."can anyone tell what is this also sir your work is very appreciable...
Jaisu 10 months ago
jarvis quite function not working plz help me out from this
ratan 9 months, 4 weeks ago
Harry bhai mere Listen function exit nhi ho raha. Wo kewal listening hi kr raha h
manojkumarmk 9 months, 3 weeks ago
hello when I run this program it shows error $ python jarvismjk.py Traceback (most recent call last): File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3\__init__.py", line 44, in init eng = _activeEngines[driverName] File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\weakref.py", line 137, in __getitem__ o = self.data[key]() KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "jarvismjk.py", line 9, in <module> engine = pyttsx3.init('sapi5') File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3\__init__.py", line 46, in init eng = engine(driverName, debug) TypeError: 'module' object is not callable
manojkumarmk 9 months, 3 weeks ago
please help me -- I need help my whatsapp no. is 8285064459 Please help I have a problem in coding of python
zarif 8 months, 1 week ago
I have add a command called search.It will search any kind of website.
rocoov 8 months ago
harry sir Getting an error my logs are present at del.dog/rocoov Please Help me out
ElectroIoT 8 months ago
Many Many Thanks ...........
Omkar 7 months ago
Hey there i am planning this for final year project . Even i want to learn machine . Since die hard fan of iron man
Karansxa 6 months, 3 weeks ago
Harry Sir error occured what to do? --------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~\Anaconda3\lib\site-packages\pyttsx3\__init__.py in init(driverName, debug) 19 try: ---> 20 eng = _activeEngines[driverName] 21 except KeyError: ~\Anaconda3\lib\weakref.py in __getitem__(self, key) 136 self._commit_removals() --> 137 o = self.data[key]() 138 if o is None: KeyError: 'sapi5'
capspid4133Y 6 months, 3 weeks ago
pip is not recognized help me
yasho 6 months, 2 weeks ago
thanks a lot bhaiya, now i adding many many more commands to jarvis and speanding at least 3-4 hours on it in a day, i am learning python,javascript,c from you
sushanta 6 months, 2 weeks ago
hello harry bhai main kal rat se try karrahahun kuchha error dikharaha hai..kya karu.(sushantapatra92@gmail.com)error: "C:\Program Files (x86)\Python38-32\python.exe" C:/Users/WETDEV/PycharmProjects/python-learn/jarvis.py Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio import pyaudio ModuleNotFoundError: No module named 'pyaudio' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/WETDEV/PycharmProjects/python-learn/jarvis.py", line 65, in <module> query = takeCommand().lower() File "C:/Users/WETDEV/PycharmProjects/python-learn/jarvis.py", line 37, in takeCommand with sr.Microphone() as source: File "C:\Program Files (x86)\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__ self.pyaudio_module = self.get_pyaudio() File "C:\Program Files (x86)\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 110, in get_pyaudio raise AttributeError("Could not find PyAudio; check installation") AttributeError: Could not find PyAudio; check installation Process finished with exit code 1
Arpit_007 6 months ago
The only thing that i have to say is "love you bro"
DK@123 5 months, 4 weeks ago
sir, i am facing this problem. please help me. i installed all modules in vscode. Traceback (most recent call last): File "d:/python full course/Jarvis/Jarvis.py", line 69, in <module> query = takeCommand().lower() File "d:/python full course/Jarvis/Jarvis.py", line 39, in takeCommand with sr.Microphone() as source: File "C:\Users\DK\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 138, in __enter__ self.audio.open( File "C:\Users\DK\AppData\Local\Programs\Python\Python38\lib\site-packages\pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "C:\Users\DK\AppData\Local\Programs\Python\Python38\lib\site-packages\pyaudio.py", line 441, in __init__ self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error
blindkrypto 4 months, 3 weeks ago
error aa raha hai Undefined variable 'r'
afjal 4 months, 2 weeks ago
Hi Harry I try to run this same code but it is not working kindly guide me... Traceback (most recent call last): File "C:\python37\lib\site-packages\pyttsx3\__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\python37\lib\weakref.py", line 137, in __getitem__ o = self.data[key]() KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module> from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\python37\lib\site-packages\comtypes\gen\__init__.py) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\python37\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE return _win_functype_cache[(restype, argtypes, flags)] KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.automation.LP_tagVARIANT'>, <class 'ctypes.c_long'>), 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/AFJAL/PycharmProjects/quickschoolassistance37/quickschoolAssistance.py", line 9, in <module> engine = pyttsx3.init('sapi5') File "C:\python37\lib\site-packages\pyttsx3\__init__.py", line 22, in init eng = Engine(driverName, debug) File "C:\python37\lib\site-packages\pyttsx3\engine.py", line 30, in __init__ self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\python37\lib\site-packages\pyttsx3\driver.py", line 50, in __init__ self._module = importlib.import_module(name) File "C:\python37\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module> engine = comtypes.client.CreateObject("SAPI.SpVoice") File "C:\python37\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject return _manage(obj, clsid, interface=interface) File "C:\python37\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage obj = GetBestInterface(obj) File "C:\python37\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface mod = GetModule(tlib) File "C:\python37\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\python37\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\python37\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import return __import__(fullname, globals(), locals(), ['DUMMY']) File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\python37\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 421, in <module> ( ['out', 'retval'], POINTER(POINTER(ISpeechObjectTokens)), 'ObjectTokens' )), File "C:\python37\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__ self._make_methods(value) File "C:\python37\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\python37\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.
afjal 4 months, 2 weeks ago
reply me harry please...
acharyadipak 4 months, 2 weeks ago
Hello Sir, While I was making or learning your code to make Jarvis I got lost of errors so please help me with that. I even tried coping your code from this website but still I got same problem I tried in pycharm as well as In Visual Stdio
Kishan 4 months, 1 week ago
when i try to run it shown an error File "jarvis.py", line 45 print(f"User said: {query}\n") ^ SyntaxError: invalid syntax please help
BhosaleYash 4 months, 1 week ago
Hi harry bhai I am learning python.. I tried to copy your Jarvis code and tried to run it.. But at the line of engine = pyttsx3.init('sapi5') Error was thrown .. Can u plzz explain reason behind it...
anurag@123 2 months, 4 weeks ago
i also get the same error ,i post this as comment in the comment section. waiting reply .
Sean98 4 months ago
Hi Harry Bro, I have been following this tutorial but i have some problems that i am facing please help i really need this assistant C:\Users\SEAN JONES\Desktop\pthn> & "C:/Users/SEAN JONES/AppData/Local/Programs/Python/Python38/python.exe" "c:/Users/SEAN JONES/Desktop/pthn/JARVIS/jarvis.py" Traceback (most recent call last): File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in __getitem__ o = self.data[key]() KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:/Users/SEAN JONES/Desktop/pthn/JARVIS/jarvis.py", line 9, in <module> engine = pyttsx3.init('sapi5') File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__ self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in __init__ self._module = importlib.import_module(name) File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\Users\SEAN JONES\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module> import pythoncom ModuleNotFoundError: No module named 'pythoncom' PS C:\Users\SEAN JONES\Desktop\pthn>
sabaafrin 3 months, 4 weeks ago
Thank you so much harry bro.
nakulnandhu 3 months, 3 weeks ago
bhai ye "except Exception as e:" mein"Unused variable 'e'pylint(unused-variable)" dikha raha hei. kyakaru?
Mrinal 3 months, 3 weeks ago
Can i use this code for pydriod( in android phone)??
javedkhan 3 months, 1 week ago
very good teaching style.....but i am having a problem in the jarvis....when i give command to jarvis with the help of headphones then its all right but when i unplug the headphones and then use it, it just stuck to listening although microphone of laptop is working perfectly
jay@0306 3 months ago
KeyError: 'sapi5'. it comes what should i do .plzzzz help quickly.
Amit812 3 months ago
Hi Harry please help i am facing following issue : Running setup.py install for pyaudio ... error ERROR: Command errored out with exit status 1: command: 'c:\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Amit\\AppData\\Local\\Temp\\pip-install-g08lbway\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\Amit\\AppData\\Local\\Temp\\pip-install-g08lbway\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Amit\AppData\Local\Temp\pip-record-bwshm6jj\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python\python38-32\Include\pyaudio' cwd: C:\Users\Amit\AppData\Local\Temp\pip-install-g08lbway\pyaudio\ Complete output (13 lines): running install running build running build_py creating build creating build\lib.win32-3.8 copying src\pyaudio.py -> build\lib.win32-3.8 running build_ext building '_portaudio' extension creating build\temp.win32-3.8 creating build\temp.win32-3.8\Release creating build\temp.win32-3.8\Release\src cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\python\python38-32\include -Ic:\python\python38-32\include /Tcsrc/_portaudiomodule.c /Fobuild\temp.win32-3.8\Release\src/_portaudiomodule.obj error: command 'cl.exe' failed: No such file or directory ---------------------------------------- ERROR: Command errored out with exit status 1: 'c:\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Amit\\AppData\\Local\\Temp\\pip-install-g08lbway\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\Amit\\AppData\\Local\\Temp\\pip-install-g08lbway\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Amit\AppData\Local\Temp\pip-record-bwshm6jj\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python\python38-32\Include\pyaudio' Check the logs for full command output.
Amit812 3 months ago
Try this it will work : 1> pip install pipwin after that 2> pipwin install pyaudio it works in my case
Dhruv7 3 months ago
harry when I run the code it raises and artributError said pyaudio is not install
Maxsinshots 3 months ago
You are Great Harry. Always have Respect in Heart For You... I Will not be that I If you will not be there..
anurag@123 2 months, 4 weeks ago
correy bhai theri is an error come while executing the program:- engine = pyttsx3.init('sapi5')
ab31 2 months, 3 weeks ago
hey harry how can i get jarvis source code
Ganpat 2 months, 2 weeks ago
sir ,while executing your code its showing error error: C:\python3.8\python.exe C:/Users/Ganpat/PycharmProjects/first/practice.py Traceback (most recent call last): File "C:\python3.8\lib\site-packages\speech_recognition\__init__.py", line 29, in <module> from urllib import urlencode ImportError: cannot import name 'urlencode' from 'urllib' (C:\python3.8\lib\urllib\__init__.py) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Ganpat/PycharmProjects/first/practice.py", line 2, in <module> import speech_recognition as sr #pip install speechRecognition File "C:\python3.8\lib\site-packages\speech_recognition\__init__.py", line 33, in <module> from urllib.request import Request, urlopen File "C:\python3.8\lib\urllib\request.py", line 88, in <module> import http.client File "C:\python3.8\lib\http\client.py", line 71, in <module> import email.parser File "C:\python3.8\lib\email\parser.py", line 12, in <module> from email.feedparser import FeedParser, BytesFeedParser File "C:\python3.8\lib\email\feedparser.py", line 27, in <module> from email._policybase import compat32 File "C:\python3.8\lib\email\_policybase.py", line 9, in <module> from email.utils import _has_surrogates File "C:\python3.8\lib\email\utils.py", line 33, in <module> from email._parseaddr import quote File "C:\python3.8\lib\email\_parseaddr.py", line 16, in <module> import time, calendar File "C:\python3.8\lib\calendar.py", line 50, in <module> class _localized_month: File "C:\python3.8\lib\calendar.py", line 52, in _localized_month _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)] File "C:\python3.8\lib\calendar.py", line 52, in <listcomp> _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)] AttributeError: module 'datetime' has no attribute 'date'
Raja931 2 months, 1 week ago
Harry bhai I have problem in visual studio code modulenotfounderror no module named python com
anikesh922 2 months ago
Harry Bhaiya plz help me out, mujhe apna project banana hai aur next monday ko online class hone pe dikhana bhi hai. bhaiya plz emergency hai, mujhe isme problem aa rhi h. maine har tareeke se try karke dekh liya hai har baar ye "pyAudio is not found" dikhata hai aur maine har tareeke se karke dekh liya hai par ho nhi rha h bhaiya plz help kar do.
ashvins_tech 1 month, 4 weeks ago
I am getting this problem Traceback (most recent call last): File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/pyttsx3/__init__.py", line 20, in init eng = _activeEngines[driverName] File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/weakref.py", line 131, in __getitem__ o = self.data[key]() KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/ashvinbhagat/PycharmProjects/untitled1/main.py", line 9, in <module> engine = pyttsx3.init('sapi5') File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init eng = Engine(driverName, debug) File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in __init__ self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in __init__ self._module = importlib.import_module(name) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/pyttsx3/drivers/sapi5.py", line 1, in <module> import comtypes.client # Importing comtypes.client will make the gen subpackage File "/Users/ashvinbhagat/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/comtypes/__init__.py", line 23, in <module> from _ctypes import COMError ImportError: cannot import name 'COMError' from '_ctypes' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload/_ctypes.cpython-38-darwin.so)
siddhant762 1 month, 2 weeks ago
Sir I am facing problem while running the code in Pycharm as well as In Visual Studio Code too. IDE say's that ("module not found pythoncom") I didn't get it, I've downloaded the module but where I install it I don't know. I've also sent you message on instagram with screenshot of problem. I tried #pip install pythoncom command too. Sir please help me
aman97703 1 month, 2 weeks ago
listen is not working in my computer.... sir pls tell me some ideas how to resolve this problem.........
shahnoor14 1 month, 2 weeks ago
sir there is an error in my program:it says install pythoncom..........i tried installing it by pip install pythoncom but it did not install
SaiHimaja 1 month, 1 week ago
same problem
Deep07 1 month, 2 weeks ago
Thank you sir i will try to make these
Satvinder05 1 month, 1 week ago
Traceback (most recent call last): File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__ o = self.data[key]() KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "e:\PYTHON\MEGA_PROJECTS\JARVIS\jarvis.py", line 4, in <module> engine = pyttsx3.init('sapi5') File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__ self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__ self._module = importlib.import_module(name) File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\Users\Satvinder\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module> import pythoncom ModuleNotFoundError: No module named 'pythoncom' SIR PROBLEM PLEASE HELP!!!! AS SOON AS POSSIBLE
SaiHimaja 1 month, 1 week ago
No module named 'pythoncom' is coming how to solve this
SaiHimaja 1 month, 1 week ago
please reply
SaiHimaja 1 month, 1 week ago
main microsoft ravi(indian) ko voices mein add karna chahti hun tho kaise karoon
Vishal12221 1 month ago
import pyttsx3 import datetime import speech_recognition as sr engine=pyttsx3.init() engine = pyttsx3.init("sapi5") voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) def speak(audio): rate = engine.getProperty('rate') engine.setProperty('rate',170) engine.say(audio) engine.runAndWait() def wishme(): if int(datetime.datetime.now().hour)<=12 and int(datetime.datetime.now().hour)>=0: speak("good morning Sir i am jarvis How can i help you") elif int(datetime.datetime.now().hour)>=12 and int(datetime.datetime.now().hour)<=18: speak("good afternoon Sir i am jarvis How can i help you") else: speak("good evening Sir i am jarvis How can i help you") def command(): r = sr.Recognizer() with sr.Microphone() as source: print("Listening...") r.pause_threshold = 1 r.energy_threshold=300 audio = r.listen(source) try: print("Recognizing...") r.adjust_for_ambient_noise(audio,duration=70) query = r.recognize_google(audio, language='en-in') print(f"User said: {query}\n") except Exception as e: # print(e) print("Say that again please...") return "None" return query command() this is my code it not doesn't recognize what i say and everytime its say "say again " plzz help
shubh0037 1 month ago
Below is the error i am getting sir:-- Traceback (most recent call last): File "C:\Users\Shubh\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE return _win_functype_cache[(restype, argtypes, flags)] KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.c_long'>, <class 'comtypes.LP_POINTER(IUIAutomationTextRange)'>), 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:/PYTHON/Jarvis/jarvis.py", line 8, in <module> import pywinauto File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\__init__.py", line 89, in <module> from . import findwindows File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\findwindows.py", line 42, in <module> from . import controls File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module> from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module> from ..uia_defines import IUIA File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module> pattern_ids = _build_pattern_ids_dic() File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic if hasattr(IUIA().ui_automation_client, cls_name): File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__ cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__ self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll') File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import return __import__(fullname, globals(), locals(), ['DUMMY']) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\gen\_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py", line 1155, in <module> ( ['out', 'retval'], POINTER(POINTER(IUIAutomationElementArray)), 'children' )), File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__ self._make_methods(value) File "C:\Users\Shubh\venv\Python3.7\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\Users\Shubh\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
quinn_lvr 1 month ago
Any possible way that i can make web requests in sketch, like home automations etcc.... & any possible way to automate application functions?? and any possiblw way to extend this to my android devices aroud, auto run etc..
harsh7827 4 weeks, 1 day ago
Harry bhai, I was Trying to Built this Program but Speech Recognizer is taking Input from Speakers instead of Microphone what should I do... Kindly Reply
harry 3 weeks ago
Speech Recognizer is taking Input from Speakers - What does that mean?
harsh7827 2 weeks, 4 days ago
Sir when I am playing a video or audio then only speech recognizer listens... not my voice
rishi026 3 weeks ago
it's not work in python 3.8
Jaykatariya 2 weeks ago
Harry bro, I created it, it's awesome but if we could add wolfram alpha calculation in ur source code it would help to do homework. Bro,please tell how to add.
Jaykatariya 1 week, 6 days ago
Please Reply
Zoldyk_Arya 1 week, 4 days ago
I'm getting this error, Please help! TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.
justin 1 week, 3 days ago
harry bhai plzz batao aapne vo last mai exit code kaise dala tha
abigail 1 week ago
i had an error for keyword sapi5, to overcome that i used installing this module named as pywin32 and rerun it .

Resources

No downloadable resources for this video. If you think you need anything, please post it in the QnA!

Course Announcements

Any Course related announcements will be posted here

Course Content