-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfun.py
More file actions
185 lines (143 loc) · 5.15 KB
/
Copy pathfun.py
File metadata and controls
185 lines (143 loc) · 5.15 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/python3
import speech_recognition as sr
import numpy as np
import os, time, datetime, cv2, pyttsx3, urllib, urllib.parse, pafy, webbrowser
from bs4 import BeautifulSoup
from textblob import TextBlob
from nltk.corpus import wordnet
from textblob.classifiers import NaiveBayesClassifier
with open('document.json', 'r') as fp:
cl = NaiveBayesClassifier(fp, format="json")
engine = pyttsx3.init()
def tts(voice_input_data):
engine = pyttsx3.init()
# voices = engine.getProperty('voices')
# engine.setProperty('voice', voices[1].id)
engine.say(voice_input_data)
engine.runAndWait()
def camera():
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
img_counter = 0
cam = cv2.VideoCapture(0)
print("hit 'space' to click a pic\n hit 'Esc' to quit")
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k % 256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k % 256 == 32:
# SPACE pressed
img_name = ("/home/manish/Desktop/" + date +
"opencv_frame_{}.png".format(img_counter))
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
class WordDef(sr.Recognizer):
def listen(self, source, timeout=None):
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
class VideoPlay(sr.Recognizer):
def listen(self, source, timeout=None):
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
def Video_Search():
#engine.say("what video you want to search")
#engine.runAndWait()
tts("what video you want to play")
sr.Recognizer = VideoPlay
sa = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = sa.listen(source)
srch_query = sa.recognize_google(audio)
query = urllib.parse.quote(srch_query)
url = "https://www.youtube.com/results?search_query=" + query
response = urllib.request.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
zx = 0
for vid in soup.findAll(attrs={'class': 'yt-uix-tile-link'}):
x = ('https://youtube.com/' + vid['href'])
print(zx)
if x != None and zx == 1:
recv_url = x
break
zx += 1
video = pafy.new(recv_url)
best = video.getbest()
playurl = best.url
webbrowser.open(playurl)
class Search(sr.Recognizer):
def listen(self, source, timeout=None):
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
def Search_Anything():
#engine.say("what do you want to search")
#engine.runAndWait()
tts("what do you want to search")
sr.Recognizer = Search
sa = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = sa.listen(source)
user_input = sa.recognize_google(audio)
result = webbrowser.open("https://www.google.com/search?q=" + user_input)
class SentAnalyzer(sr.Recognizer):
def listen(self, source, timeout=None):
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
def sentiment_Analyzer():
#engine.say("Speak a sentence")
#engine.runAndWait()
tts("Speak a sentence")
sr.Recognizer = SentAnalyzer
sa = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = sa.listen(source)
user_input = sa.recognize_google(audio)
analysis = TextBlob(user_input)
print(analysis.sentiment)
if analysis.sentiment.polarity == 0:
engine.say("your sentiment is nutral")
engine.runAndWait()
elif analysis.sentiment.polarity > 0:
engine.say("your sentiment is positive")
engine.runAndWait()
elif analysis.sentiment.polarity < 0:
engine.say("your sentiment is negative")
engine.runAndWait()
def word_def_ex():
#engine.say("speak a word")
#engine.runAndWait()
tts("speak a word")
sr.Recognizer = WordDef
w = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = w.listen(source)
user_input1 = w.recognize_google(audio)
result = wordnet.synsets(user_input1)
re = (result[0].definition())
tts(re)
print(re)
print(result[0].examples())
def bot_help():
print(
"__camera()__ ---\n say 'take picture' for open camera\n press 'space' for clicking picture\n press 'Esc' for quit...\n"
)
print("\n__sentiment_Analysis()__ ---\n say 'analysis' for sentiment analysis\n")
print("\n__word_def_ex()__ ---\n say 'definition' for asking word's definition\n")
print("\n__Video_Search()__ ---\n say 'video' for search for a video\n")
print("\n__Search_Anything()__ ---\n say 'search' for search anything\n")