-
Notifications
You must be signed in to change notification settings - Fork 13
/
run.py
36 lines (28 loc) · 941 Bytes
/
run.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
from gtts import gTTS
import speech_recognition as sr
from googletrans import Translator
import playsound
import os
translator = Translator()
def translator_fun(text):
return translator.translate(text, src='si', dest='en')
def text_to_voice(text_data):
myobj = gTTS(text=text_data, lang='en', slow=False)
myobj.save("cache_file.mp3")
playsound.playsound("cache_file.mp3")
os.remove("cache_file.mp3")
while True:
rec = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
rec.pause_threshold = 1
audio = rec.listen(source, phrase_time_limit=10)
try:
print("Processing...")
spoken_text = rec.recognize_google(audio, language='si')
print("Translating...")
tamil_version = translator_fun(spoken_text)
print("Text to Speech...")
text_to_voice(tamil_version.text)
except Exception as e:
print(e)