import pyttsx3 import speech_recognition as sr import wikipedia import webbrowser import datetime import speedtest import wolframalpha import tkinter from tkinter import * engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') # print(voices[1].id) engine.setProperty('voice', voices[1].id) engine.setProperty('rate', 130) 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 < 14: speak("Good Afternoon!") else: speak("Good Evening!") def takeCommand(): r = sr.Recognizer() with sr.Microphone() as source: print("Listening....") r.pause_threshold = 1 r.adjust_for_ambient_noise(source, duration=1) audio = r.listen(source) try: print("Recognising...") query = r.recognize_google(audio, language='en-in') print("User said:", query,) speak(query) except Exception as e: # print(e) print("Say that again please...") return "None" return query if __name__ == "__main__": wishme() speak("Hi! I am Veronica Your personal virtual assistant. So how can I help you") print("If u want to know about me speak HELP and i will I help you") while True: query = takeCommand().lower() if query == "EXIT": speak("THE WINDOW IS GOING TO BE CLOSED") import time time.sleep(2) break elif "help" in query: print('''This is Veronica I CAN PERFORM ACTIONS LIKE :- OPENING YOUTUBE AND GOOGLE :-SETTING UP A TIMER :- GETTING UP UR IP :-DATE(TODAY) AND TIME :-SHOWING INFORMATION FROM WIKIPEDIA :- ANSWERING BASIC QUERIES :- IF U WANT TO QUIT SAY EXIT ''','\n') speak('''This is Veronica I can perform Actions like... Opening google and youtube. setting up a timer.getting your IP. Getting information from wikipedia. answering various queries''') elif "open youtube" in query: control = webbrowser.get() control.open("http://www.youtube.com") speak("Youtube is bieng opened") print("Youtube Has Been Opened",'\n') elif 'open google' in query: controller = webbrowser.get() controller.open("http://www.google.com") speak("Google is bieng opened") print("GOOGLE Has Been Opened",'\n') elif 'timer' in query: speak("A screen will appear on which you can type the time in seconds and when ur time is complete u will get a notification in your notification bar") # from tkinter import * def set_timer(): t = int(B.get()) print(t) import time from plyer import notification import time from plyer import notification if __name__=="__main__": time.sleep(t) print('''YOUR TIMER IS OVER''','\n') notification.notify( title = "TIMER OVER", message=" YOUR TIMER IS OVER" , timeout=2 ) root = Tk() root.title("TIMER") root.geometry("200x100") root.resizable(width=FALSE, height=FALSE) l1 = Label(root,font= ("arial 20")) l1.grid(row = 2 , column = 2) A = StringVar() B = Entry(root,textvariable= A) B.grid(row = 3, column =2) C1 = Button(root,text = "set",width = 20,command = set_timer) C1.grid(row = 4, column = 2) root.mainloop() elif query == "IP": import requests response = requests.get('https://httpbin.org/ip') speak(response) print(response,'\n') elif '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 'time' in query: from datetime import datetime today = datetime.now().time() print(today,'\n') speak(today) elif query == "none": continue else : client = wolframalpha.Client("8PW43U-UT9VA2R3UK") print(query) res = client.query(query) output = next(res.results).text print(output,'\n') speak(output)