mirror of
https://github.com/maglore9900/max_headroom.git
synced 2025-06-06 19:45:31 +00:00
.
This commit is contained in:
parent
3a39a17eb9
commit
23bae0ad50
34
modules/stt.py
Normal file
34
modules/stt.py
Normal 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
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
speechrecognition
|
||||
pyaudio
|
||||
pyttsx3
|
Loading…
x
Reference in New Issue
Block a user