-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (51 loc) · 1.96 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
import speech_recognition as sr
import pyttsx3
from datetime import datetime
import pywhatkit
import wikipedia
# Selecione o audio para reconhecimento
audio = sr.Recognizer()
# Inicia a IA
maquina = pyttsx3.init()
while True:
def executa_comando():
try:
with sr.Microphone() as source:
print('Ouvindo..')
voz = audio.listen(source) # Lista as entradas de audio
comando = audio.recognize_google(voz, language='pt-BR')
comando = comando.lower() # Converte as entradas de audio para minisiculo
if 'tina' in comando:
comando = comando.replace('tina', '') # Troca a entrada 'tina' por nada
maquina.runAndWait()
except:
print('Microfone OFF')
return comando
def comando_voz_usuario():
comando = executa_comando()
if 'horas' in comando:
hora = datetime.now().strftime('%H:%M')
maquina.say('Agora são' + hora)
maquina.runAndWait()
elif 'dia' in comando:
data = datetime.today()
datatxt = f'{data.day} do {data.month}'
maquina.say('Hoje é dia ' + datatxt)
maquina.runAndWait()
elif 'procure por' in comando:
procurar = comando.replace('procure por', '')
wikipedia.set_lang('pt')
resultado = wikipedia.summary(procurar,2)
print(resultado)
maquina.say(resultado)
maquina.runAndWait()
elif 'escutar' in comando:
musica = comando.replace('escutar', '')
resultado = pywhatkit.playonyt(musica)
maquina.say('Tocando Musica')
maquina.runAndWait()
elif 'enviar mensagem' in comando:
msg = pywhatkit.sendwhatmsg_instantly('+5562984824354', 'Olá Mãe Bom dia!', 15, True, 2)
maquina.say('Mensagem enviada!')
maquina.runAndWait()
comando_voz_usuario()