-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest1.py
More file actions
105 lines (88 loc) · 3.08 KB
/
test1.py
File metadata and controls
105 lines (88 loc) · 3.08 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
#!/usr/bin/python3
import speech_recognition as sr
import numpy as np
import pyttsx3, os, time, datetime, cv2, urllib, urllib.parse, pafy, webbrowser
from nltk.corpus import wordnet
from fun import tts, sentiment_Analyzer, camera, word_def_ex, Video_Search, Search_Anything, bot_help
from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
with open('document.json', 'r') as fp:
cl = NaiveBayesClassifier(fp, format="json")
engine = pyttsx3.init()
g = ('greetings')
x = ('photo')
y = ('sentiment_analysis')
z = ('word_definition')
p = ('video')
s = ('search')
h = ('help')
q = ('quit')
class CustomSource(sr.Microphone):
def init(self, device_index=None, sample_rate=16000, chunk_size=1024):
print("about to initialize microphone")
result = super(self.__class__, self).init()
print("done initializing microphone")
return result
class CustomRecognizer(sr.Recognizer):
def listen(self, source, timeout=20):
# print ("instructions!!! \n")
time.sleep(0.6)
# print ("say 'take picture' for clicking a picture")
# print("say 'analysis' for sentence analysis")
# print ("say 'definition' for word's definition")
# print ("say 'video' for playing video")
# print("say 'search' for search anything")
# print("OR....")
# print("speak a valid command \n !!Caution expert pronunciation Required ")
# time.sleep(1)
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
sr.Recognizer = CustomRecognizer
sr.Microphone = CustomSource
while True:
while True:
try:
r = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = r.listen(source)
user_input_command = r.recognize_google(audio)
print(user_input_command)
if user_input_command == 'hello':
break
except:
continue
try:
r = sr.Recognizer()
with sr.Microphone(chunk_size=512) as source:
audio = r.listen(source)
user_input_command = r.recognize_google(audio)
output = cl.classify(user_input_command)
if output == g:
engine.say("hii, i am your personal assistent")
engine.runAndWait()
elif output == x:
print("press q to click")
print("Camera is about to open!!!!!")
time.sleep(1)
camera()
elif output:
sentiment_Analyzer()
elif output == z:
word_def_ex()
elif output == p:
Video_Search()
elif output == s:
Search_Anything()
elif output == h:
bot_help()
elif output == q:
break
else:
print('nothing')
y = os.system(user_input_command)
print(y)
#print("you said: " + r.recognize_google(audio))
except:
os.system('echo " this is not a command,try again" | festival --tts')