-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioCommSys.py
32 lines (25 loc) · 873 Bytes
/
AudioCommSys.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
from gtts import gTTS
import os
from io import BytesIO
from playsound import playsound
language = 'en'
def speech_to_text():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
print("Please say something....")
audio = recognizer.listen(source, timeout=2)
try:
print("You said: \n" + recognizer.recognize_google(audio))
return (recognizer.recognize_google(audio))
except Exception as e:
print("Error: " + str(e))
def text_to_speech(text):
output = gTTS(text=text, lang=language, slow=False)
output.save(os.getcwd() + f"/audio/output-{text}.mp3")
playsound(os.getcwd() + f"/audio/output-{text}.mp3")
def main():
text_to_speech("testing")
if __name__ == "__main__":
main()