|
| 1 | +import pyttsx3 |
| 2 | +import datetime |
| 3 | +import speech_recognition as sr |
| 4 | +import wikipedia |
| 5 | +import webbrowser |
| 6 | +import subprocess |
| 7 | +import os |
| 8 | + |
| 9 | +engine = pyttsx3.init('sapi5') |
| 10 | +voices = engine.getProperty('voices') |
| 11 | +# print(voices[0].id) |
| 12 | +engine.setProperty('voice', voices[0].id) |
| 13 | + |
| 14 | + |
| 15 | +def speak(audio): |
| 16 | + engine.say(audio) |
| 17 | + engine.runAndWait() |
| 18 | + |
| 19 | + |
| 20 | +def wishMe(): |
| 21 | + hour = int(datetime.datetime.now().hour) |
| 22 | + if hour >= 0 and hour < 12: |
| 23 | + speak("good morning sir") |
| 24 | + elif hour >= 12 and hour < 18: |
| 25 | + speak("good afternoon sir") |
| 26 | + else: |
| 27 | + speak("Good evening sir") |
| 28 | + |
| 29 | + speak("I am Friday, your virtual assistant running on python?") |
| 30 | + speak("How may I help you?") |
| 31 | + |
| 32 | +def takeCommand(): |
| 33 | + r = sr.Recognizer() |
| 34 | + with sr.Microphone() as source: |
| 35 | + print("Listening..") |
| 36 | + r.pause_threshold = 1 |
| 37 | + audio = r.listen(source) |
| 38 | + |
| 39 | + try: |
| 40 | + print("Recognizing...") |
| 41 | + query = r.recognize_google(audio, language='en-in') |
| 42 | + print(f"User said: {query}\n") |
| 43 | + except Exception as e: |
| 44 | + print(e) |
| 45 | + |
| 46 | + print("Please repeat your command..") |
| 47 | + return "None" |
| 48 | + return query |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + wishMe() |
| 53 | +while True: |
| 54 | + query = takeCommand().lower() |
| 55 | + |
| 56 | + if 'wikipedia' in query: |
| 57 | + speak('Searching wikipedia...') |
| 58 | + query = query.replace("wikipedia", "") |
| 59 | + results = wikipedia.summary(query, sentences=1) |
| 60 | + speak("According to what i found on wikipedia") |
| 61 | + print(results) |
| 62 | + speak(results) |
| 63 | + elif 'what can you do' in query: |
| 64 | + speak("I can search for something in wikipedia,") |
| 65 | + speak("open websites, play friends or even open your whatsapp.") |
| 66 | + speak("If you are interested to read some amazing blogs say open my blog.") |
| 67 | + elif 'who are you' in query: |
| 68 | + speak("I am friday, the successor of Jarvis.") |
| 69 | + elif 'open youtube' in query: |
| 70 | + webbrowser.open("youtube.com") |
| 71 | + elif 'open google' in query: |
| 72 | + webbrowser.open("google.com") |
| 73 | + elif 'open instagram' in query: |
| 74 | + webbrowser.open("instagram.com") |
| 75 | + elif 'open my blog' in query: |
| 76 | + webbrowser.open("codehustler.dev") |
| 77 | + elif 'open stackoverflow' in query: |
| 78 | + webbrowser.open("stackoverflow.com") |
| 79 | + elif 'the time' in query: |
| 80 | + strTime = datetime.datetime.now().strftime("%H:%M:%S") |
| 81 | + speak(f"Sir, the time is {strTime}") |
| 82 | + elif 'open whatsapp' in query: |
| 83 | + subprocess.call( |
| 84 | + 'C:\\Users\\hp\\AppData\\Local\\WhatsApp\\WhatsApp.exe') |
| 85 | + elif 'play friends' in query: |
| 86 | + friends_dir = 'G:\\F.R.I.E.N.D.S' |
| 87 | + friends = os.listdir(friends_dir) |
| 88 | + print(friends) |
| 89 | + os.startfile(os.path.join(friends_dir, friends[0])) |
| 90 | + elif 'terminate' in query: |
| 91 | + speak("Goodbye sir see you soon.") |
| 92 | + exit() |
0 commit comments