-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (51 loc) · 1.8 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
import speech_recognition as sr
from time_date import dt
from weather import weather,set_city
from t2s import text_to_speech
from news import news
import nltk
from summarization import summary
nltk.download('stopwords')
r = sr.Recognizer()
m = sr.Microphone()
valid = False
while not valid:
city = input("enter the city you live in:")
valid = set_city
start = True
def stp_words(Mytext):
stopwords = nltk.corpus.stopwords.words('english')
str = ''
for word in Mytext:
if word not in stopwords:
return word
while(start):
try:
with m as source:
r.adjust_for_ambient_noise(source)
print("the date and time are :", dt())
print("start speaking")
audio = r.listen(source)
Mytext = r.recognize_google(audio)
Mytext = Mytext.lower()
print(Mytext)
if("time" in Mytext):
date_time = dt()
text_to_speech(" the time is " + str(date_time))
if("date" in Mytext):
date_time = dt()
text_to_speech(" the time is " + str(date_time))
if("weather" in Mytext):
temperature, humidity, pressure, cond = weather(city)
text_to_speech("the temperature is " + str(temperature) + "and" + str(cond))
if("news" in Mytext):
keyword = stp_words(Mytext)
story = news(keyword)
summ = summary(story)
text_to_speech(summ)
if(Mytext[len(Mytext)-4:] == 'quit'):
start = False
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
except sr.UnknownValueError:
print("unknown error occured")