|
| 1 | +import speech_recognition as sr |
| 2 | +import pyttsx3 |
| 3 | +import datetime |
| 4 | +import wikipedia |
| 5 | +# Artificial Intelligence actually access the Webbrowser |
| 6 | +import webbrowser |
| 7 | +import time |
| 8 | +import ecapture as ec |
| 9 | +import pywhatkit |
| 10 | +# OS can access your operating system |
| 11 | +import os |
| 12 | +import subprocess |
| 13 | +import wolframalpha |
| 14 | +# Json save everything like a database |
| 15 | +import json |
| 16 | +import requests |
| 17 | + |
| 18 | +print('Sk. Salahuddin - Morning 01 Batch') |
| 19 | +engine=pyttsx3.init('sapi5') |
| 20 | + |
| 21 | +voices = engine.getProperty('voices') |
| 22 | +engine.setProperty('voice', 'voices[1].id') |
| 23 | + |
| 24 | +def speak(text): |
| 25 | + engine.say(text) |
| 26 | + engine.runAndWait |
| 27 | + |
| 28 | +def esshan(): |
| 29 | + hour=datetime.datetime.now().hour |
| 30 | + if hour>=0 and hour<12: |
| 31 | + speak("Good Morning!") |
| 32 | + elif hour>=12 and hour<18: |
| 33 | + speak("Good Afternoon") |
| 34 | + else: |
| 35 | + speak("Good evening!") |
| 36 | + |
| 37 | +def takeCommand(): |
| 38 | + record=sr.Recognizer() |
| 39 | + with sr.Microphone() as source: |
| 40 | + print("I'm Listening...") |
| 41 | + audio = record.listen(source) |
| 42 | + |
| 43 | + try: |
| 44 | + statement = record.recognize_google(audio,language='en-in') |
| 45 | + print(f"user said:{statement}\n") |
| 46 | + |
| 47 | + except Exception as e: |
| 48 | + speak("I didnt hear you, please say that again") |
| 49 | + return "none" |
| 50 | + return statement |
| 51 | + |
| 52 | +speak("Opening, Please wait for a few seconds") |
| 53 | +esshan() |
| 54 | + |
| 55 | +if __name__=='__main__': |
| 56 | + while True: |
| 57 | + speak("what can i do for you?") |
| 58 | + statement = takeCommand().lower() |
| 59 | + if statement == 0: |
| 60 | + continue |
| 61 | + |
| 62 | + if "good bye" in statement or "ok bye" in statement or "turn off" in statement: |
| 63 | + speak ('See you later!') |
| 64 | + break |
| 65 | + |
| 66 | + if 'wikipedia' in statement: |
| 67 | + speak('Searching the wiki') |
| 68 | + statement = statement.replace("wikipedia", "") |
| 69 | + results = wikipedia.summary(statement, sentences=3) |
| 70 | + speak("according to the wiki") |
| 71 | + speak(results) |
| 72 | + |
| 73 | + elif 'time' in statement: |
| 74 | + clock_time = datetime.datetime.now().strftime('%I:%M %p') |
| 75 | + print(f"Your local time is = {clock_time} is Bangladesh Time") |
| 76 | + |
| 77 | + elif 'open youtube' in statement: |
| 78 | + webbrowser.open_new_tab("https://youtube.com") |
| 79 | + speak("Opening YouTube, wait for a while") |
| 80 | + time.sleep(3) |
| 81 | + |
| 82 | + elif 'play' in statement: |
| 83 | + song = statement.replace("play", "") |
| 84 | + speak('playing' + song) |
| 85 | + pywhatkit.playonyt(song) |
| 86 | + |
| 87 | + elif 'open facebook' in statement: |
| 88 | + webbrowser.open_new_tab("https://facebook.com") |
| 89 | + speak("Opening Facebook, wait for a while") |
| 90 | + time.sleep(3) |
| 91 | + |
| 92 | + elif 'open twitter' in statement: |
| 93 | + webbrowser.open_new_tab("https://twitter.com") |
| 94 | + speak("Opening Twitter, wait for a while") |
| 95 | + time.sleep(3) |
| 96 | + |
| 97 | + elif 'open google' in statement: |
| 98 | + webbrowser.open_new_tab("https://www.google.com") |
| 99 | + speak("Opening Google Chrome, wait for a while") |
| 100 | + time.sleep(5) |
| 101 | + |
| 102 | + elif 'open gmail' in statement: |
| 103 | + webbrowser.open_new_tab("gmail.com") |
| 104 | + speak("Opening Gmail, wait for a while") |
| 105 | + time.sleep(5) |
0 commit comments