From e54738e7253a2cbf304ab2663c62b8d9858e4821 Mon Sep 17 00:00:00 2001 From: Technerd brainiac <72148261+Harsha200105@users.noreply.github.com> Date: Fri, 1 Oct 2021 19:21:32 +0530 Subject: [PATCH] Add files via upload added python code Desktop Virtual Assistant --- Jarvis2.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Jarvis2.py diff --git a/Jarvis2.py b/Jarvis2.py new file mode 100644 index 0000000..01bcfac --- /dev/null +++ b/Jarvis2.py @@ -0,0 +1,97 @@ +import pyttsx3 +import speech_recognition as sr +import datetime +import wikipedia +import webbrowser +import os +import smtplib + +print("Initializing Jarvis....") +MASTER = "Harsha" + + +engine = pyttsx3.init('nsss') +voices = engine.getProperty('voices') +engine.setProperty('voice', voices[0].id) + +def speak(text): + engine.say(text) + engine.runAndWait() + + + +def wishMe(): + hour = datetime.datetime.now().hour + # print(hour) + if hour >= 0 and hour < 12: + speak("Good Morning" + MASTER) + + elif hour >= 12 and hour < 18: + speak("Good Afternoon" + MASTER) + + else: + speak("Good Evening" + MASTER) + + # speak("Hey I am Jarvis. How may I help you") + + +# This is where our programme begins.... + +def takeCommand(): + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening....") + r.pause_threshold = 0.5 + audio = r.listen(source) + + query = " " + try: + print("Recognizing....") + query = r.recognize_google(audio, language='en-in') + print("user said: " + query) + + except sr.UnknownValueError: + print("Sorry Could You please try again") + + except Exception as e: + print(e) + print("Say That Again Please") + query = None + + return query + + +speak("Initializing Jarvis....") +wishMe() +query = takeCommand() + +# logic for executing basic tasks +if 'wikipedia' in query.lower(): + speak('Searching wikipedia....') + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences = 2) + print(results) + speak(results) + + +elif 'open youtube' in query.lower(): + + webbrowser.open("youtube.com") + url = 'https://www.youtube.com/' + + chrome_path = 'open -a /Applications/Google\ Chrome.app %s' + webbrowser.get(chrome_path).open(url) + +elif 'on google' in query.lower(): + + webbrowser.open("google.com") + url = 'https://www.google.com/' + + chrome_path = 'open -a /Applications/Google\ Chrome.app %s' + webbrowser.get(chrome_path).open(url) + +# elif 'play music' in query.lower(): +# songs_dir = "//Users//bindu//Desktop//imusic" +# songs = os.listdir(songs_dir) +# print(songs) +# os.open(os.path.join(songs_dir, songs[0]))