-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsistente Virtual.py
More file actions
133 lines (111 loc) · 3.64 KB
/
Asistente Virtual.py
File metadata and controls
133 lines (111 loc) · 3.64 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
from cgitb import lookup
import pyttsx3
#import pywhatkit
import speech_recognition as sr
import webbrowser
import datetime
import os
import yfinance as yf
import pyjokes
import wikipedia
#funcion que escucha el audio y lo retorna como texto usando google
def transform():
r = sr.Recognizer()
with sr.Microphone() as fuente:
r.pause_threshold = 0.8
frase = r.listen(fuente)
try:
print ('Recibido')
q = r.recognize_google(frase, language="es")
return (q)
except sr.UnknownValueError:
print('Perdona no entendi')
return 'Esperando...'
except sr.RequestError:
print('Perdón el servicio esta caido')
return 'Esperando...'
except:
return "Eperando..."
def speaking(message):
engine = pyttsx3.init()
engine.say(message)
engine.runAndWait()
#Cambiar la voz de la pc
engine = pyttsx3.init()
id = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ES-MX_SABINA_11.0'
engine.setProperty('voice', id)
#retornar el dia de la semana
def query_day():
day = datetime.date.today()
#print(day)
weekday = day.weekday()
#print (weekday)
mapping = {
0:'Lunes',1:'Martes',2:'Miercoles',3:'Jueves',4:'Viernes',5:'Sabado',6:'Domingo'
}
try:
speaking(f'Hoy es {mapping[weekday]}')
except:
pass
#retornar el tiempo
def query_time():
time = datetime.datetime.now().strftime("%I:%M:%S")
print(time)
speaking(f'Son las {time}')
def welcome():
speaking('Hola, mi nombre es Sabina y soy tu asistente personal. ¿En qué te puedo ayudar?')
#Funcion principal
def principal():
welcome()
start = True
while (start):
q = transform().lower()
if 'abre youtube' in q:
speaking('Abriendo Youtube, un segundo.')
webbrowser.open('https://www.youtube.com')
continue
elif 'abre google' in q:
speaking('Abriendo Google, un segundo.')
webbrowser.open('https://www.google.com')
continue
elif 'dime la fecha' in q:
query_day()
continue
elif 'dime la hora' in q:
query_time()
continue
elif 'apagar' in q:
speaking('Sale pues')
break
elif 'de wikipedia' in q:
speaking('Buscando en wikipedia')
q = q.replace('wikipedia' , '')
result = wikipedia.summary(q, sentences = 2)
speaking(result)
continue
elif 'tu nombre' in q:
speaking('Mi nombre es Sabina')
continue
#elif 'en la web' in q:
pywhatkit.search(q)
speaking('esto es lo que encontré')
continue
#elif 'reproduce' in q:
speaking(f'reproduciendo {q}')
pywhatkit.playonyt(q)
continue
elif 'broma' in q:
speaking(pyjokes.get_joke())
continue
elif 'precio de stock' in q:
search = q.split('de')[-1].strip()
lookup = {'apple':'AAPL','amazon':'AMZN','google':'GOOGL'}
try:
stock = lookup[search]
stock = yf.Ticker(stock)
currentprice = stock.info["regularMarketPrice"]
speaking(f'lo encontré, el precio de {search} es {currentprice}')
except:
speaking('No encontré datos al respecto')
continue
principal()