diff --git a/Personal-Desktop-Assisstant-by-VoiceAI.py b/Personal-Desktop-Assisstant-by-VoiceAI.py new file mode 100644 index 0000000..ac07135 --- /dev/null +++ b/Personal-Desktop-Assisstant-by-VoiceAI.py @@ -0,0 +1,140 @@ +import speech_recognition as sr +import pyttsx3 +import datetime +import wikipedia +import webbrowser +import os +import time +import subprocess +from ecapture import ecapture as ec +import wolframalpha +import json +import requests +engine=pyttsx3.init('sapi5') +voices=engine.getProperty('voices') +engine.setProperty('voice','voices[0].id') +def speak(text): + engine.say(text) + engine.runAndWait() +def wishMe(): + hour=datetime.datetime.now().hour + if hour>=0 and hour<12: + speak("Hello,Good Morning") + print("Hello,Good Morning") + elif hour>=12 and hour<18: + speak("Hello,Good Afternoon") + print("Hello,Good Afternoon") + else: + speak("Hello,Good Evening") + print("Hello,Good Evening") +def takeCommand(): + r=sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + audio=r.listen(source) + + try: + statement=r.recognize_google(audio,language='en-in') + print(f"user said:{statement}\n") + + except Exception as e: + speak("Pardon me, please say that again") + return "None" + return statement + +print("Loading your assistant Anonymous") +speak("Loading your assistant Anonymous") +wishMe() +if __name__=='__main__': + + + while True: + speak("Tell me how can I help you now?") + statement = takeCommand().lower() + if statement==0: + continue + if "good bye" in statement or "ok bye" in statement or "stop" in statement: + speak('your personal assistant Anonymous is shutting down,Good bye') + print('your personal assistant Anonymous is shutting down,Good bye') + break + if 'who is' in statement: + person = statement.replace('who is','') + info = wikipedia.summary(person,1) + print(info) + speak(info) + + elif 'open youtube' in statement: + webbrowser.open_new_tab("https://www.youtube.com") + speak("youtube is open now") + time.sleep(5) + + elif 'open google' in statement: + webbrowser.open_new_tab("https://www.google.com") + speak("Google chrome is open now") + time.sleep(5) + + elif 'open gmail' in statement: + webbrowser.open_new_tab("gmail.com") + speak("Google Mail open now") + time.sleep(5) + elif 'time' in statement: + strTime=datetime.datetime.now().strftime("%H:%M:%S") + speak(f"the time is {strTime}") + elif 'search' in statement: + statement = statement.replace("search", "") + webbrowser.open_new_tab(statement) + time.sleep(5) + elif 'ask' in statement: + speak('I can answer to computational and geographical questions and what question do you want to ask now') + question=takeCommand() + app_id="Your api id " + client = wolframalpha.Client('R2K75H-7ELALHR35X') + res = client.query(question) + answer = next(res.results).text + speak(answer) + print(answer) + elif 'who are you' in statement or 'what can you do' in statement: + speak('I am Anonymous version 1 point O your personal assistant. I am programmed to minor tasks like' + 'opening youtube,google chrome, gmail and stackoverflow ,predict time,take a photo,search wikipedia,predict weather' + 'In different cities, get top headline news from times of india and you can ask me computational or geographical questions too!') + + + elif "who made you" in statement or "who created you" in statement or "who discovered you" in statement: + speak("I was built by Bansal") + print("I was built by Bansal") + elif "weather" in statement: + api_key="Your api key" + base_url="https://api.openweathermap.org/data/2.5/weather?" + speak("whats the city name") + city_name=takeCommand() + complete_url=base_url+"appid="+api_key+"&q="+city_name + response = requests.get(complete_url) + x=response.json() + if x["cod"]!="404": + y=x["main"] + current_temperature = y["temp"] + current_humidiy = y["humidity"] + z = x["weather"] + weather_description = z[0]["description"] + speak(" Temperature in kelvin unit is " + + str(current_temperature) + + "\n humidity in percentage is " + + str(current_humidiy) + + "\n description " + + str(weather_description)) + print(" Temperature in kelvin unit = " + + str(current_temperature) + + "\n humidity (in percentage) = " + + str(current_humidiy) + + "\n description = " + + str(weather_description)) + elif "open stackoverflow" in statement: + webbrowser.open_new_tab("https://stackoverflow.com/login") + speak("Here is stackoverflow") + + + elif "log off" in statement or "sign out" in statement: + speak("Ok , your pc will log off in 10 sec make sure you exit from all applications") + subprocess.call(["shutdown", "/l"]) + +time.sleep(3)