This commit is contained in:
maglore9900 2024-08-17 20:12:39 -04:00
parent 3a39a17eb9
commit 23bae0ad50
2 changed files with 37 additions and 0 deletions

34
modules/stt.py Normal file
View File

@ -0,0 +1,34 @@
import speech_recognition as sr
import pyttsx3
class STT:
def __init__(self):
self.recognizer = sr.Recognizer()
self.microphone = sr.Microphone()
self.engine = pyttsx3.init()
self.engine.setProperty('rate', 150)
def listen(self):
with self.microphone as source:
print("Listening...")
audio = self.recognizer.listen(source)
try:
text = self.recognizer.recognize_google(audio)
print("You said: ", text)
return text
except sr.UnknownValueError:
print("Sorry, I didn't get that.")
except sr.RequestError as e:
print("Sorry, I couldn't request results; {0}".format(e))
def speak(self, text):
self.engine.say(text)
self.engine.runAndWait()
# while True:
# stt = STT()
# text = stt.listen()
# stt.speak(text)
# del stt
# print("Listening again...")

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
speechrecognition
pyaudio
pyttsx3