Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 58 additions & 49 deletions venv/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import wikipedia
import webbrowser
import os
import sys
import platform
import time
import subprocess
from ecapture import ecapture as ec
Expand All @@ -13,66 +15,87 @@


print('Loading your AI personal assistant - G One')

engine=pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
engine.setProperty('voice','voices[0].id')
system = platform.system()

if system == "Windows":
print("System: Windows")
print("Loading Sapi5 engine")
engine_to_use = "sapi5"
elif system == "Darwin":
print("System: MacOS")
print("Loading nsss engine")
engine_to_use = "nsss"
else:
# Linux, Posix, BSD, etc.
print("System: %s" % system)
print("Loading espeak engine")
engine_to_use = "espeak"
try:
engine = pyttsx3.init(engine_to_use)
except Exception as err:
print("Could not load the TTS engine. Do you have it properly installed?")
print("Error:")
print(err)
sys.exit("Critical Error")

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:
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:
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()
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio=r.listen(source)
audio = r.listen(source)

try:
statement=r.recognize_google(audio,language='en-in')
print(f"user said:{statement}\n")
statement = r.recognize_google(audio, language='en-in')
print("user said:%s" % statement)

except Exception as e:
speak("Pardon me, please say that again")
return "None"
return statement


speak("Loading your AI personal assistant G-One")
wishMe()


if __name__=='__main__':

if __name__ == '__main__':

while True:
speak("Tell me how can I help you now?")
statement = takeCommand().lower()
if statement==0:
if statement == 0:
continue

if "good bye" in statement or "ok bye" in statement or "stop" in statement:
speak('your personal assistant G-one is shutting down,Good bye')
print('your personal assistant G-one is shutting down,Good bye')
break



if 'wikipedia' in statement:
speak('Searching Wikipedia...')
statement =statement.replace("wikipedia", "")
statement = statement.replace("wikipedia", "")
results = wikipedia.summary(statement, sentences=3)
speak("According to Wikipedia")
print(results)
Expand All @@ -94,15 +117,15 @@ def takeCommand():
time.sleep(5)

elif "weather" in statement:
api_key="8ef61edcf1c576d65d836254e11ea420"
base_url="https://api.openweathermap.org/data/2.5/weather?"
api_key = "8ef61edcf1c576d65d836254e11ea420"
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
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"]
x = response.json()
if x["cod"] != "404":
y = x["main"]
current_temperature = y["temp"]
current_humidiy = y["humidity"]
z = x["weather"]
Expand All @@ -123,18 +146,15 @@ def takeCommand():
else:
speak(" City Not Found ")



elif 'time' in statement:
strTime=datetime.datetime.now().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak("the time is %s" % strTime)

elif 'who are you' in statement or 'what can you do' in statement:
speak('I am G-one version 1 point O your persoanl assistant. I am programmed to minor tasks like'
'opening youtube,google chrome,gmail and stackoverflow ,predict time,take a photo,search wikipedia,predict weather'
'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 Mirthula")
print("I was built by Mirthula")
Expand All @@ -144,43 +164,32 @@ def takeCommand():
speak("Here is stackoverflow")

elif 'news' in statement:
news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines")
news = webbrowser.open_new_tab(
"https://timesofindia.indiatimes.com/home/headlines")
speak('Here are some headlines from the Times of India,Happy reading')
time.sleep(6)

elif "camera" in statement or "take a photo" in statement:
ec.capture(0,"robo camera","img.jpg")
ec.capture(0, "robo camera", "img.jpg")

elif 'search' in statement:
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="R2K75H-7ELALHR35X"
question = takeCommand()
app_id = "R2K75H-7ELALHR35X"
client = wolframalpha.Client('R2K75H-7ELALHR35X')
res = client.query(question)
answer = next(res.results).text
speak(answer)
print(answer)


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")
speak(
"Ok , your pc will log off in 10 sec make sure you exit from all applications")
subprocess.call(["shutdown", "/l"])

time.sleep(3)