-
Notifications
You must be signed in to change notification settings - Fork 0
/
luca.py
149 lines (113 loc) · 4.22 KB
/
luca.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# :copyright: (c) 2019-present Aniket Bhattacharjee
# :license: MIT, see LICENSE for more details.
import pyttsx3
import speech_recognition as sr
import datetime
import os
import wikipedia
from requests import get
import webbrowser
import sys
import pywhatkit
from bs4 import BeautifulSoup
import requests
import pywikihow
from pywikihow import search_wikihow
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
engine.setProperty('voices', voices[0].id)
def speak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source,timeout=10,phrase_time_limit=30)
try:
print("Recognizing...")
query = r.recognize_google(audio, language= 'en-in')
print(f"User Said: {query}")
except Exception as e:
speak("Sir can you please repeat...")
return "none"
return query
def wish():
hour = int(datetime.datetime.now().hour)
specimen = datetime.datetime.now().strftime('%I:%M %p')
if hour>=0 and hour<=12:
speak(f"Good Morning Sir its {specimen}")
elif hour>12 and hour<10:
speak(f"Good Afternoon Sir its {specimen}")
else:
speak(f"Good Evening Sir its {specimen}")
speak("How can i help")
if __name__ == "__main__":
wish()
while True:
query = takecommand().lower()
if "wikipedia" in query:
speak("Searching for the results in Wikipedia...")
query = query.replace("wikipedia","")
results = wikipedia.summary(query, sentences=2)
speak("According to wikipedia")
speak(results)
elif "google" in query:
speak("Sir what should i search in google")
cm = takecommand().lower()
webbrowser.open("www.google.com/search?q=" + cm)
elif "go to sleep" in query:
speak("Ok sir have a good day")
sys.exit()
elif "time now" in query:
global time
time = "The time is " + datetime.datetime.now().strftime('%I:%M %p')
speak(time)
elif "temperature in" in query:
search = query.replace("temperature in","")
url = f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text, "html.parser")
temp = data.find("div" ,class_="BNeawe").text
weather = f"Currently in {search} it is {temp} with hazz"
speak(weather)
sys.exit()
elif "play" in query:
song = query.replace('play', '')
speak('playing ' + song)
pywhatkit.playonyt(song)
sys.exit()
elif "stop" in query:
print("Program Terminated")
speak("Hope you had a wonderful time")
sys.exit()
elif "no thanks" in query:
print("Program Terminated")
speak("Hope you had a wonderful time")
sys.exit()
elif "date" in query:
date = datetime.datetime.now().strftime('%d %B %Y')
speak(f"Today's date is {date}")
elif "news" in query:
speak("Here is the latest news")
webbrowser.open("https://news.google.co.in/")
sys.exit()
elif "how" in query:
speak(" i am opening a video which can help you")
pywhatkit.playonyt(query)
speak("thank you")
sys.exit()
elif "flip a coin" in query:
speak("fliping a coin")
webbrowser.open("https://www.google.com/search?q=flip+a+coin")
sys.exit()
else:
sir = query.replace("ok luca", "")
webbrowser.open("www.google.com/search?q=" + sir)
results = wikipedia.summary(query, sentences=2)
speak("According to wikipedia")
speak(results)
sys.exit()