-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (53 loc) · 1.62 KB
/
main.py
File metadata and controls
79 lines (53 loc) · 1.62 KB
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
import pyttsx3
import datetime
import speech_recognition as sr
engine = pyttsx3.init() # initializes the pyttsx3 modules
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
new_speak_rate = 150
engine.setProperty('rate', new_speak_rate)
def speak(audio):
engine.say(audio)
engine.runAndWait()
# speak("Hello World! I am Totto . How can I help you?")
def time():
time_now = datetime.datetime.now().strftime("%H : %M : %S")
speak(time_now)
def date():
year = datetime.datetime.now().year # Extracts current year
mon = datetime.datetime.now().month # Extracts current month
day = datetime.datetime.now().day # Extracts current day
speak("Current date is")
speak(day)
speak(mon)
speak(year)
def wishme():
# speak("Hello Sir!")
# time()
# date()
hour = datetime.datetime.now().hour
if 6 <= hour <= 12:
speak("Good morning sir")
elif 12 < hour <= 15:
speak("good afternoon sir")
elif 16 < hour <= 24:
speak("Good evening sir")
else:
speak("good Night sir")
speak("Totto is at your service")
# wishme()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing..")
query = r.recognize_google(audio, 'en=US')
print(query)
except Exception as e:
print(e)
speak("Could you please repeat again")
return "none"
takeCommand()