-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoice.py
42 lines (35 loc) · 1.28 KB
/
voice.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
import speech_recognition as sr
import pyttsx3
"""
Project - F.R.I.D.A.Y.
@author Cortez, Manuel
@date 06/01/2025
Clase encargada del reconocimiento de voz y activacion del asistente.
"""
class Voice:
def __init__(self):
self.recognizer = sr.Recognizer()
self.engine = pyttsx3.init()
self.engine.setProperty("voice", self.engine.getProperty("voices")[0].id)
def activation(self):
with sr.Microphone() as source:
print("F.R.I.D.A.Y.")
self.recognizer.adjust_for_ambient_noise(source)
audio = self.recognizer.listen(source)
try:
text = self.recognizer.recognize_google(audio, language = "es").lower()
return "viernes" in text or "despierta" in text
except sr.UnknownValueError:
return False
def listen(self):
with sr.Microphone() as source:
print("Escuchando...")
self.recognizer.adjust_for_ambient_noise(source)
audio = self.recognizer.listen(source)
try:
return self.recognizer.recognize_google(audio, language = "es").lower()
except sr.UnknownValueError:
return ""
def speak(self, text):
self.engine.say(text)
self.engine.runAndWait()