-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasistente_virtual.py
202 lines (171 loc) · 8.93 KB
/
asistente_virtual.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import sys, os, time, re, webbrowser speech_recognition as sr
from gtts import gTTS
from random import randint
from urllib import request, parse
print('opciones:')
print('[diga]abrir editor de texto',
'[diga]abrir word','[diga]abrir explorador',
'[diga]abrir administrador de tareas',
'[diga]dime un chiste','[diga]buscar en youtube',
'[diga]buscar en google','[diga]escribir nota',
sep='\n'
)
count=0
number=0
lang='es-es'
# obtain audio
while True:
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("hola, diga algo:")
audio = r.listen(source)
try:
said=r.recognize_google(audio,language=lang)
print("usted dijo:" + said)
if re.match('.brir editor de texto',said):
tts = gTTS(text="abriendo block de notas", lang='es')
tts.save("bnota.mp3")
os.system("start bnota.mp3")
os.startfile('notepad.exe')
elif re.match('.....bir nota',said):
tts = gTTS(text="que quiere escribir", lang='es')
tts.save("nota.mp3")
os.system("start nota.mp3")
print('escuchando:')
audio = r.listen(source)
try:
said=r.recognize_google(audio,language=lang)
listen=True
except Exception as e:
listen=False
print(e)
input('no pude escuchar pulse (enter) y repita de nuevo...')
if listen == True:
file='doc.txt'
if os.path.exists(file):
while path.exists(file):
number+=1
newnum=str(number)
file='doc'+newnum+'.txt'
doc=open(file,'a')
else:
doc=open(file,'a')
for i in said:
count+=1
doc.write(i)
if count==75:
doc.write('\n')
count=0
doc.close
tts = gTTS(text="su nota se a guardado en:"+file, lang='es')
tts.save("nsave.mp3")
os.system("start nsave.mp3")
elif re.match('.brir .or',said):
tts = gTTS(text="abriendo word", lang='es')
tts.save("word.mp3")
os.system("start word.mp3")
os.startfile('winword.exe')
elif re.match('.brir ..plorador',said):
tts = gTTS(text="abriendo explorador", lang='es')
tts.save("iexplore.mp3")
os.system("start iexplore.mp3")
os.startfile('iexplore.exe')
elif re.match('.brir ....nistrador de tareas',said):
tts = gTTS(text="abriendo administrador de tareas", lang='es')
tts.save("Taskmgr.mp3")
os.system("start Taskmgr.mp3")
os.startfile('Taskmgr.exe')
elif re.match('........chiste',said):
random=randint(1,4)
if random==1:
tts = gTTS(text="Llega Pepito al parque, se le acerca "+
"un amiguito y le dice:- Eh Pepito, tienes "+
"puesto un zapato café y otro negro.Pepito "+
"le contesta:- Y eso no es nada, en mi casa"
" tengo otro par igualito.", lang='es')
tts.save("cuento1.mp3")
os.system("start cuento1.mp3")
elif random==2:
tts = gTTS(text="- Veamos, Pepito, ¿qué puedes decirme "+
"de la muerte de Cristóbal Colón?- Que lo "+
"siento muchísimo, señorita.", lang='es')
tts.save("cuento2.mp3")
os.system("start cuento2.mp3")
else:
tts = gTTS(text="La profesora le dice a Pepito:- A ver "+
"Pepito, si yo digo: fui rica, es pasado, "+
"pero si yo digo: soy hermosa, ¿qué es?."+
"¡Demasiada imaginación profesora!.", lang='es')
tts.save("cuento3.mp3")
os.system("start cuento3.mp3")
elif re.match('.uscar.....ou.ub.',said):
tts = gTTS(text="que desea buscar?", lang='es')
tts.save("search.mp3")
os.system("start search.mp3")
time.sleep(2)
print('buscar:')
audio = r.listen(source)
try:
buscar=r.recognize_google(audio,language=lang)
print("usted dijo:" + buscar)
listen=True
except Exception as e:
listen=False
print(e)
input('no pude escuchar pulse (enter) y repita de nuevo...')
if listen == True:
tts = gTTS(text="quiere que le muestre la lista o le reprodusca el video?", lang='es')
tts.save("youtube.mp3")
os.system("start youtube.mp3")
time.sleep(4)
print('buscar:')
audio = r.listen(source)
try:
said = r.recognize_google(audio,language=lang)
print("usted dijo:" + said)
listen = True
except Exception as e:
listen = False
print(e)
input('no pude escuchar pulse (enter) y repita de nuevo...')
if listen == True:
query_string = parse.urlencode({"search_query" : buscar})
if re.match('........lista',said):
webbrowser.open("http://www.youtube.com/results?"+query_string)
else:
html_content = request.urlopen("http://www.youtube.com/results?" + query_string)
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
webbrowser.open("http://www.youtube.com/watch?v=" + search_results[0])
elif re.match('.uscar.....oogle',said):
tts = gTTS(text="que desea buscar?", lang='es')
tts.save("search.mp3")
os.system("start search.mp3")
time.sleep(2)
print('buscar:')
audio = r.listen(source)
try:
buscar=r.recognize_google(audio,language=lang)
print("usted dijo:" + buscar)
listen = True
except Exception as e:
listen = False
print(e)
input('no pude escuchar pulse (enter) y repita de nuevo...')
if listen == True:
tts = gTTS(text="buscando en google", lang='es')
tts.save("google.mp3")
os.system("start google.mp3")
time.sleep(2)
query_string = parse.urlencode({"q" : buscar})
webbrowser.open("https://www.google.com.do/search?"+query_string)
else:
input('no pude escuchar pulse (enter) y repita de nuevo...')
else:
tts = gTTS(text="la orden no esta en mis opciones o dijo algo mal", lang='es')
tts.save("error.mp3")
os.system("start error.mp3")
input('ok')
except Exception as e:
print(e)
input('no pude escuchar pulse (enter) y repita de nuevo...')