-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (55 loc) · 2.14 KB
/
main.py
File metadata and controls
67 lines (55 loc) · 2.14 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
import speech_recognition as sr
import webbrowser
import time
import playsound
import os
import random
from gtts import gTTS
rec = sr.Recognizer()
def record_audio(ask = False):
with sr.Microphone() as source:
if ask:
sexta_feira_speak(ask)
audio = rec.listen(source)
try:
voice_data = rec.recognize_google(audio)
except sr.UnknownValueError:
sexta_feira_speak('Desculpe, eu não entendi o que você disse.')
exit()
except sr.RequestError:
sexta_feira_speak('Desculpe, meu serviço de assistencia está desativado.')
exit()
return voice_data
def sexta_feira_speak(audio_string):
text_to_speech = gTTS(text = audio_string,lang = 'pt')
ran = random.randint(1,10000000)
audio_file = 'audio-' + str(ran) + '.mp3'
text_to_speech.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file)
def respond(voice_data):
what_time = ['quantas horas sao', 'que horas sao', 'que hora e essa']
search = ['realizar pesquisa', 'fazer pesquisa', 'pesquisar']
find_location = ['procurar localização', 'encontrar localização', 'localização']
if 'qual o seu nome' in voice_data:
sexta_feira_speak('Meu nome é Sexta-Feira, é um prazer ser sua assistente!')
elif voice_data in what_time:
sexta_feira_speak(time.ctime())
elif voice_data in search :
search_query = record_audio('O que deseja pesquisar?')
url = 'https://google.com/search?q=' + search_query
webbrowser.get().open(url)
sexta_feira_speak('Aqui está o que eu encontrei para ' + search_query)
elif voice_data in find_location:
location = record_audio('Qual localização você deseja encontrar?')
url = 'https://www.google.com/maps/place/' + location + '/&'
webbrowser.get().open(url)
sexta_feira_speak('Aqui está a localização que eu encontrei para ' + location)
elif 'sair' in voice_data:
exit()
time.sleep(1)
sexta_feira_speak('Olá, como posso ajudá-lo?')
while 1:
voice_data = record_audio()
respond(voice_data)