-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecognizer-AI.py
More file actions
70 lines (51 loc) · 2.18 KB
/
recognizer-AI.py
File metadata and controls
70 lines (51 loc) · 2.18 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
import speech_recognition as sr
import re
import os
def listen_microphone():
# Enable microphone
microphone = sr.Recognizer()
# Using microphone
with sr.Microphone() as source:
# Reduces ambient noise
microphone.adjust_for_ambient_noise(source)
print("\nOlá, diga como posso te ajudar?\n")
# Stores the audio
audio = microphone.listen(source)
try:
# Uses speech pattern recognizer for brazilian language
phrase = microphone.recognize_google(audio, language='pt-BR')
phrase = phrase.lower()
##---------- Action options ----------##
if "abrir navegador" in phrase:
os.system("start chrome.exe")
elif "qual a previsão do tempo" in phrase:
os.system("start chrome.exe www.google.com/search?q=previsão+do+tempo")
elif "abrir tradutor" in phrase:
os.system("start chrome.exe https://translate.google.com.br/")
elif "abrir excel" in phrase:
os.system("start excel.exe")
elif "abrir bloco de notas" in phrase:
os.system("start notepad.exe")
elif "abrir gerenciador de arquivos" in phrase:
os.system("start explorer.exe")
elif "abrir terminal" in phrase:
os.system("start")
elif "o que é" in phrase:
with sr.Microphone() as query:
microphone.adjust_for_ambient_noise(query)
print("O que deseja pesquisar?")
search_query = microphone.listen(query)
try:
phrase = microphone.recognize_google(search_query, language='pt-BR')
search = re.sub("o que é ","", phrase)
search = '+'.join(search.split(' '))
os.system(f"start Chrome.exe www.google.com/search?q={search}")
# If not recognizer print a message
except sr.UnknownValueError:
print('\nDesculpe, não entendi.')
# Returns the phrase
print("Você disse: " + phrase)
# If not recognizer print a message
except sr.UnknownValueError:
print('\nDesculpe, não entendi.')
listen_microphone()