-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeech.py
32 lines (24 loc) · 844 Bytes
/
Speech.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
import speech_recognition as sr
import pyttsx3
class TTS:
"""Class that handles text-to-speech functionality."""
def __init__(self):
self.tts = pyttsx3.init()
self.tts.setProperty("rate", 150)
def text_to_speech(self, text):
self.tts.say(text)
self.tts.runAndWait()
class STT:
"""Class that handles speech-to-text functionality."""
def __init__(self):
self.rec = sr.Recognizer()
self.mic = sr.Microphone()
def speech_to_text(self):
with self.mic as source:
self.rec.adjust_for_ambient_noise(source)
print("Speak into your microphone: ")
audio = self.rec.listen(source)
print("Done!")
text = self.rec.recognize_google(audio)
print("Your speech was recognized as: " + text)
return text