-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (87 loc) · 2.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
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
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import os
# cambio de nombre
name = 'eva'
#Flag
flag = 1
# ====================Convertidor de voz a texto=================
listener = sr.Recognizer()
engine = pyttsx3.init()
'''Esto funcionaba para elegir las voces peroahora solo tiene 1 en ingles'''
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
# editing default configuration
engine. setProperty('rate', 178)
engine.setProperty('volume', 0.7)
'''---------coonvierte texto a voz---------'''
def talk(text):
engine.say(text)
engine.runAndWait()
def listen():
flag = 1
try:
with sr.Microphone() as source:
print("Escuchando...")
voice = listener.listen(source)
rec = listener.recognize_google(voice, language='es-ES')
rec = rec.lower()
# solo contesta si lo llamas por su nombre
if name in rec:
rec = rec.replace(name, '')
flag = run(rec)
else:
talk("Creo que no te entiendo ")
except:
pass
return flag
#--------------------------------------------RUN------------------------------------------
def run(rec):
global flag
'''##############################Arreglar Funcion de la hora########################'''
if 'hora' in rec:
hrs = datetime.datetime().now().strftime('%H:%M')
talk("Son las " + hrs)
elif 'hola' in rec:
talk('Hola, buenos días')
elif 'reproduce' in rec:
search = rec.replace('reproduce', '')
talk('Reproduciendo' + search)
# reprouce la busqueda en youtube
pywhatkit.playonyt(search)
elif 'busca' in rec:
order = rec.replace('busca', '')
wikipedia.set_lang('es')
info = wikipedia.summary(order, 1)
talk(info)
elif 'chiste' in rec:
joke = pyjokes.get_joke('es')
print(joke)
talk(joke)
elif 'apagar' in rec:
os.system('shutdown /s /t 30')
elif ('cancelar' in rec) and ('apagado' in rec):
os.system('shutdown /a')
elif 'abrir' in rec:
program = rec.replace('abrir ', '')
program = program.replace(' ', '')
talk('abriendo' + program)
direccion = "L:/Projects/VirtualAssistant/DirectAccess/"
os.system(direccion + program + '.lnk')
elif 'fondo' in rec:
talk('Abriendo WallpaperEngine...')
direccion = "L:/Projects/VirtualAssistant/DirectAccess/"
os.system(direccion + 'fondos.url')
elif 'chau' in rec:
flag = 0
talk("Adios Señor...")
else:
talk("Creo que no te entiendo")
return flag
while flag:
flag = listen()
# ---------------------------------------------------------------