Make your own personal assistant using python

    Hello friend today we are making our own personal assistant using python. it was not much advance, this will totally depend on the if-elif-else function which will we used in our program. You can make it fully functionable as your wish. Follow below step to make it.

  1. First download all the modules which we use to create our personal assistant, for this open your command prompt in window and type the code given below.
  2. pip install pyttsx3
    pip install os
  3. After the downloading is complete, open Python IDLE on your computer and import all the modules.
  4. #Module
    import pyttsx3
    import os
  5. Now we will set the voice of our assistant. 0 is for Male voice and 1 is for Female voice. You can choose any of them.
  6. #voice_of_assistant
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    engine.setProperty('voice', voices[0].id)
    engine.runAndWait()
  7. Now we put a some greeting message like "Hello Sir". You can choose your own greeting message that assistant will wish you.
  8. #greeting_message
    print('Hello sir')
    pyttsx3.speak('Hello sir')
    print('I am jarvis, your personal assistant\n')
    pyttsx3.speak('I am jarvis, your personal assistant')
  9. Now we take input from user.
  10. #input_from_user
    while True:    
        pyttsx3.speak('What can I do for you')
        cmd = input('What can I do for you:- ')
  11. Now we put a code that if user not give any command.
  12. #not_given_command
        if cmd == '':
            print("Sorry sir, can't recognize")
            pyttsx3.speak("Sorry sir, can't recognize")
            print('')
            continue
  13. :- Now we put a code to open application. You can choose any app from your computer.
  14. #to_open_notepad
        elif('notepad' in cmd):
            print('Opening Notepad')
            pyttsx3.speak('Opening Notepad')
            os.system('notepad')
            print('')
    
    #to_open_paint
        elif('paint' in cmd) or ('paints' in cmd) n cmd):
            print('Opening Microsoft Paint')
            pyttsx3.speak('Opening Microsoft Paint')
            os.system('mspaint')
            print('')
  15. Now we put a code that if user want to shutdown their computer.
  16. #shutdown_computer
        elif('shutdown' in cmd) or ('restart' in cmd):
            print('Ok sir shutting down your computer')
            pyttsx3.speak('Ok sir shutting down your computer')
            os.system("shutdown /s /t 1")
  17. Now we put a code that if user want to exit that application.
  18. #to_close_jarvis
        elif('exit' in cmd) or ('bye' in cmd):
            print('Sure sir bye, Have a nice day')
            pyttsx3.speak('Sure sir bye, Have a nice day')
            break
  19. Now we put a code that if user give any invalid command.
  20. #invalid_command
        else :
            print('invalid command')
            pytsx3.speak('invalid command')

    Code was completed and if you want add and more command then used Elif-function and to to open any other program you just have to put a line of code "os.startfile("address of file")". If you got any error put it on comment section. Let me know about that error.

Previous Post Next Post