|
| 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 | +# Set the voice to a female voice |
| 22 | +voices = engine.getProperty('voices') |
| 23 | +engine.setProperty("voice", voices[1].id) |
| 24 | + |
| 25 | +def speak(text): |
| 26 | + engine.say(text) |
| 27 | + engine.runAndWait() |
| 28 | + |
| 29 | +def esshan(): |
| 30 | + hour = datetime.datetime.now().hour |
| 31 | + if hour >= 0 and hour < 12: |
| 32 | + speak("Good Morning!") |
| 33 | + elif hour >= 12 and hour < 18: |
| 34 | + speak("Good Afternoon") |
| 35 | + else: |
| 36 | + speak("Good evening!") |
| 37 | + |
| 38 | +def get_weather(city): |
| 39 | + # API URL with your API key |
| 40 | + url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid=99e68c086c34059f58d3349bd4fb694c&units=metric' |
| 41 | + |
| 42 | + # Send an HTTP GET request to the API and get the response |
| 43 | + response = requests.get(url) |
| 44 | + |
| 45 | + # Check if the API call was successful |
| 46 | + if response.status_code == 200: |
| 47 | + # Parse the JSON response to get the weather information |
| 48 | + weather = response.json() |
| 49 | + |
| 50 | + # Extract the relevant weather information from the JSON response |
| 51 | + temperature = weather['main']['temp'] |
| 52 | + humidity = weather['main']['humidity'] |
| 53 | + description = weather['weather'][0]['description'] |
| 54 | + |
| 55 | + # Return the weather report for the city |
| 56 | + return f"The temperature in {city} is {temperature} Kelvin. The humidity is {humidity}% and the weather is {description}." |
| 57 | + else: |
| 58 | + # Return an error message if the API call was not successful |
| 59 | + return "Unable to get the weather report. Please try again later." |
| 60 | + |
| 61 | +get_weather("khulna") |
| 62 | + |
| 63 | +def takeCommand(): |
| 64 | + record = sr.Recognizer() |
| 65 | + with sr.Microphone() as source: |
| 66 | + print("I'm Listening...") |
| 67 | + audio = record.listen(source) |
| 68 | + |
| 69 | + try: |
| 70 | + statement = record.recognize_google(audio, language='en-in') |
| 71 | + print(f"user said:{statement}\n") |
| 72 | + |
| 73 | + except Exception as e: |
| 74 | + speak("I didn't hear you, please say that again") |
| 75 | + return "none" |
| 76 | + return statement.lower() |
| 77 | + |
| 78 | +speak("Opening, Please wait for a seconds") |
| 79 | +esshan() |
| 80 | + |
| 81 | +if __name__=='__main__': |
| 82 | + while True: |
| 83 | + speak("What can i do for you?") |
| 84 | + statement = takeCommand().lower() |
| 85 | + if statement == 0: |
| 86 | + continue |
| 87 | + |
| 88 | + if "good bye" in statement or "ok bye" in statement or "turn off" in statement: |
| 89 | + speak('See you later!') |
| 90 | + break |
| 91 | + |
| 92 | + if 'wikipedia' in statement: |
| 93 | + speak('Searching the wiki') |
| 94 | + statement = statement.replace("wikipedia", "") |
| 95 | + results = wikipedia.summary(statement, sentences=3) |
| 96 | + speak("according to the wiki") |
| 97 | + speak(results) |
| 98 | + |
| 99 | + elif 'weather' in statement: |
| 100 | + speak("Sure, which city?") |
| 101 | + city = takeCommand() |
| 102 | + weather_report = get_weather(city) |
| 103 | + speak(weather_report) |
| 104 | + |
| 105 | + elif 'time' in statement: |
| 106 | + now = datetime.datetime.now() |
| 107 | + date = now.strftime('%Y-%m-%d') |
| 108 | + clock = now.strftime('%I:%M %p') |
| 109 | + speak(f"Today's date is {date} and the current time is {clock}") |
| 110 | + |
| 111 | + elif 'open youtube' in statement: |
| 112 | + webbrowser.open_new_tab("https://youtube.com") |
| 113 | + speak("Opening YouTube, just wait for a while") |
| 114 | + time.sleep(3) |
| 115 | + |
| 116 | + elif 'play' in statement: |
| 117 | + song = statement.replace("play", "") |
| 118 | + speak('playing' + song) |
| 119 | + pywhatkit.playonyt(song) |
| 120 | + |
| 121 | + elif 'open facebook' in statement: |
| 122 | + webbrowser.open_new_tab("https://facebook.com") |
| 123 | + speak("Opening Facebook, just wait for a while") |
| 124 | + time.sleep(3) |
| 125 | + |
| 126 | + elif 'open twitter' in statement: |
| 127 | + webbrowser.open_new_tab("https://twitter.com") |
| 128 | + speak("Opening Twitter, just wait for a while") |
| 129 | + time.sleep(3) |
| 130 | + |
| 131 | + elif 'open google' in statement: |
| 132 | + webbrowser.open_new_tab("https://www.google.com") |
| 133 | + speak("Opening Google Chrome, just wait for a while") |
| 134 | + time.sleep(5) |
| 135 | + |
| 136 | + elif 'open gmail' in statement: |
| 137 | + webbrowser.open_new_tab("gmail.com") |
| 138 | + speak("Opening Gmail, just wait for a while") |
| 139 | + time.sleep(5) |
0 commit comments