|
| 1 | +import pyttsx3 |
| 2 | +import speech_recognition as sr |
| 3 | +import datetime |
| 4 | +import wikipedia |
| 5 | +import webbrowser |
| 6 | +import os |
| 7 | +import random |
| 8 | +import smtplib |
| 9 | + |
| 10 | +engine = pyttsx3.init('sapi5') |
| 11 | +voices = engine.getProperty('voices') |
| 12 | +# print(voices[1].id) |
| 13 | +engine.setProperty('voice',voices[1].id) |
| 14 | + |
| 15 | +def speak(audio): |
| 16 | + engine.say(audio) |
| 17 | + engine.runAndWait() |
| 18 | + |
| 19 | +def wish_me(): |
| 20 | + hour = int(datetime.datetime.now().hour) |
| 21 | + if hour >= 0 and hour <12 : |
| 22 | + speak("Good Morning Robin, How Are You!") |
| 23 | + elif hour >=12 and hour <18: |
| 24 | + speak("Good Afternoon Robin , How Are You ") |
| 25 | + else: |
| 26 | + speak("Good Evening Robin , How Are You") |
| 27 | + speak("I am jarvis, Please Tell Me How Can I Help You") |
| 28 | + |
| 29 | +def send_email(to,message): |
| 30 | + server = smtplib.SMTP('smtp.gmail.com',587) |
| 31 | + server.ehlo() |
| 32 | + server.starttls() |
| 33 | + server.login('email','your-password') |
| 34 | + server.sendmail('rsinghpooj@gmail.com',to,message) |
| 35 | + server.close() |
| 36 | + |
| 37 | +def take_command(): |
| 38 | + """ |
| 39 | + It takes speech input from the user and returns string o/p |
| 40 | + """ |
| 41 | + s = sr.Recognizer() |
| 42 | + with sr.Microphone() as source: |
| 43 | + print("Listening......") |
| 44 | + s.pause_threshold =1 # seconds of non-speaking audio before a phrase is considered complete |
| 45 | + aud = s.listen(source) |
| 46 | + |
| 47 | + try : |
| 48 | + print("Recognizing.....!") |
| 49 | + info = s.recognize_google(aud,language='en-in') |
| 50 | + print("Robin Said : ",info) |
| 51 | + |
| 52 | + |
| 53 | + except Exception as e: |
| 54 | + # print(e) |
| 55 | + print("Not Recognizing..... Please Say that Again...") |
| 56 | + return 'None' |
| 57 | + |
| 58 | + return info |
| 59 | + |
| 60 | +if __name__ == '__main__': |
| 61 | + # speak("hey, i am zara guys, how are you robin, what can i do for you") |
| 62 | + # while True:? |
| 63 | + print("Initializing Jarvis....") |
| 64 | + speak("Initializing Jarvis....") |
| 65 | + chrome_path = 'C://Program Files (x86)//Google//Chrome//Application//chrome.exe %s' |
| 66 | + mozila_path = "C:\\Program Files\\Mozilla Firefox\\firefox.exe" |
| 67 | + |
| 68 | + wish_me() |
| 69 | + while True: |
| 70 | + query = take_command() |
| 71 | + query = query.lower() |
| 72 | + if 'wikipedia' in query: |
| 73 | + speak('Searching Wikipedia....Please Wait') |
| 74 | + query = query.replace("wikipedia","") |
| 75 | + result = wikipedia.summary(query,sentences=5) |
| 76 | + speak("According To wikipedia :") |
| 77 | + print(result) |
| 78 | + speak(result) |
| 79 | + |
| 80 | + elif "open youtube " in query: |
| 81 | + # webbrowser.open("youtube.com") for default browser |
| 82 | + webbrowser.get(chrome_path).open_new_tab(url="youtube.com") |
| 83 | + |
| 84 | + elif "open google " in query: |
| 85 | + # webbrowser.open("google.com") |
| 86 | + webbrowser.get(chrome_path).open_new_tab(url="google.com") |
| 87 | + |
| 88 | + elif "open github " in query: |
| 89 | + # webbrowser.open("github.com") |
| 90 | + webbrowser.get(chrome_path).open_new_tab(url="github.com") |
| 91 | + elif " music" in query: |
| 92 | + music = "E:\\Robin\\Songs\\Main" |
| 93 | + songs = os.listdir(music) |
| 94 | + print(songs) |
| 95 | + n = random.randint(0,len(songs)-1) |
| 96 | + os.startfile(os.path.join(music,songs[n])) |
| 97 | + |
| 98 | + elif " time " in query: |
| 99 | + time1 = datetime.datetime.now().strftime("%H:%M:%S") |
| 100 | + print(time1) |
| 101 | + speak(f"Hello Robin, Now Time is {time1}") |
| 102 | + |
| 103 | + elif "visual studio" in query: |
| 104 | + visualCOde = "C:\\Users\\Robin Singh\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" |
| 105 | + os.startfile(visualCOde) |
| 106 | + |
| 107 | + elif "open git" in query: |
| 108 | + git_path = "C:\\Program Files\\Git\\git-bash.exe" |
| 109 | + os.startfile(git_path) |
| 110 | + |
| 111 | + elif "pycharm" in query: |
| 112 | + pycharm = "C:\\Program Files\\JetBrains\\PyCharm Community Edition 2019.3.2\\bin\\pycharm64.exe" |
| 113 | + os.startfile(pycharm) |
| 114 | + |
| 115 | + elif "email " in query: |
| 116 | + try: |
| 117 | + speak("Say message") |
| 118 | + message = take_command() |
| 119 | + to = "rsinghpooj@gmail.com" |
| 120 | + send_email(to,message) |
| 121 | + speak("Email has been send") |
| 122 | + |
| 123 | + except Exception as e: |
| 124 | + speak("Sorry , i m not able to send your email ") |
| 125 | + |
| 126 | + elif "jarvis quit" in query: |
| 127 | + quit() |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
0 commit comments