-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (65 loc) · 2.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import pyjokes
import wikipedia
import os
# import streamlit
# import subprocess
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
def speak(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print("Listening..")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'professor' in command:
command = command.replace('professor','')
print(command)
except Exception as e:
raise e
return command
def run_assistant():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play','')
speak('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
speak("current time is " + time)
elif 'name' in command:
speak("My name is Professor")
elif 'joke' in command:
speak(pyjokes.get_jokes())
elif 'wikipedia' in command:
speak("Searching wikipedia")
query = command.replace("wikipedia","")
results = wikipedia.summary(query,sentences=2)
speak("According to wikipedia...")
print(results)
speak(results)
elif 'generate email' in command:
os.system("app.py")
# from subprocess import call
# call(["streamlit run app.py", "-1"])
# command = 'streamlit run app.py'
# result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
elif 'detect object' in command:
os.system("object.py")
elif 'detect face' in command:
os.system("face_detect.py")
else:
print("Please say the command again")
if __name__ == "__main__":
while True:
run_assistant()