Facebook
From Python , 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 78
  1. import pyttsx3
  2. import speech_recognition as sr
  3. import wikipedia
  4. import webbrowser
  5. import datetime
  6. import speedtest
  7. import wolframalpha
  8. import tkinter
  9. from tkinter import *
  10. engine = pyttsx3.init('sapi5')
  11. voices = engine.getProperty('voices')
  12. # print(voices[1].id)
  13. engine.setProperty('voice', voices[1].id)
  14. engine.setProperty('rate', 130)
  15.  
  16.  
  17. def speak(audio):
  18.     engine.say(audio)
  19.     engine.runAndWait()
  20.  
  21.  
  22. def wishme():
  23.     hour = int(datetime.datetime.now().hour)
  24.     if hour >= 0 and hour < 12:
  25.         speak("Good Morning !")
  26.     elif hour >= 12 and hour < 14:
  27.         speak("Good Afternoon!")
  28.     else:
  29.         speak("Good Evening!")
  30.  
  31.  
  32. def takeCommand():
  33.     r = sr.Recognizer()
  34.     with sr.Microphone() as source:
  35.         print("Listening....")
  36.         r.pause_threshold = 1
  37.         r.adjust_for_ambient_noise(source, duration=1)
  38.         audio = r.listen(source)
  39.     try:
  40.         print("Recognising...")
  41.         query = r.recognize_google(audio, language='en-in')
  42.         print("User said:", query,)
  43.         speak(query)
  44.  
  45.     except Exception as e:
  46.         # print(e)
  47.         print("Say that again please...")
  48.         return "None"
  49.     return query
  50.  
  51.  
  52. if __name__ == "__main__":
  53.     wishme()
  54.     speak("Hi! I am Veronica Your personal virtual assistant. So how can I help you")
  55.     print("If u want to know about me speak HELP and i will I help you")
  56.     while True:
  57.         query = takeCommand().lower()
  58.         if query == "EXIT":
  59.             speak("THE WINDOW IS GOING TO BE CLOSED")
  60.             import time
  61.             time.sleep(2)
  62.             break
  63.  
  64.         elif "help" in query:
  65.            print('''This is Veronica
  66.            I CAN PERFORM ACTIONS LIKE
  67.            :- OPENING YOUTUBE AND GOOGLE
  68.            :-SETTING UP A TIMER
  69.            :- GETTING UP UR IP
  70.            :-DATE(TODAY) AND TIME
  71.            :-SHOWING INFORMATION FROM WIKIPEDIA
  72.            :- ANSWERING BASIC QUERIES
  73.            :- IF U WANT TO QUIT SAY EXIT
  74.            ''','\n')
  75.            speak('''This is Veronica I can perform Actions like... Opening google and youtube. setting up a timer.getting your IP.
  76.            Getting information from wikipedia. answering various queries''')
  77.        
  78.         elif  "open youtube" in query:
  79.            control = webbrowser.get()
  80.            control.open("http://www.youtube.com")
  81.            speak("Youtube is bieng opened")
  82.            print("Youtube Has Been Opened",'\n')
  83.        
  84.         elif 'open google' in query:
  85.            controller = webbrowser.get()
  86.            controller.open("http://www.google.com")
  87.            speak("Google is bieng opened")
  88.            print("GOOGLE Has Been Opened",'\n')
  89.  
  90.         elif 'timer' in query:
  91.             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")
  92.             # from tkinter import *
  93.             def set_timer():
  94.                t =  int(B.get())
  95.                print(t)
  96.                import time
  97.                from plyer import notification
  98.                import time
  99.        
  100.                from plyer import notification
  101.                if __name__=="__main__":
  102.                   time.sleep(t)
  103.                   print('''YOUR TIMER IS OVER''','\n')
  104.                   notification.notify(
  105.                   title = "TIMER OVER",
  106.                   message=" YOUR TIMER  IS OVER" ,
  107.                   timeout=2
  108.                    )
  109.             root = Tk()
  110.             root.title("TIMER")
  111.             root.geometry("200x100")
  112.             root.resizable(width=FALSE, height=FALSE)
  113.             l1 = Label(root,font= ("arial 20"))
  114.             l1.grid(row = 2 , column = 2)
  115.             A = StringVar()
  116.             B = Entry(root,textvariable= A)
  117.             B.grid(row = 3, column =2)
  118.             C1 = Button(root,text = "set",width = 20,command = set_timer)
  119.             C1.grid(row = 4, column = 2)
  120.             root.mainloop()
  121.  
  122.         elif query == "IP":
  123.             import requests
  124.             response = requests.get('https://httpbin.org/ip')
  125.             speak(response)
  126.             print(response,'\n')
  127.    
  128.         elif 'wikipedia' in query:
  129.          speak('Searching Wikipedia...')
  130.          query = query.replace("wikipedia", "")
  131.          results = wikipedia.summary(query, sentences=2)
  132.          speak("According to Wikipedia")
  133.          print(results)
  134.          speak(results)
  135.      
  136.         elif 'time' in query:
  137.           from datetime import datetime
  138.           today = datetime.now().time()
  139.           print(today,'\n')
  140.           speak(today)
  141.         elif query == "none":
  142.             continue        
  143.         else :
  144.           client = wolframalpha.Client("8PW43U-UT9VA2R3UK")
  145.           print(query)
  146.           res = client.query(query)
  147.           output = next(res.results).text
  148.           print(output,'\n')
  149.           speak(output)