Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +64 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gtts import gTTS
|
2 |
+
import streamlit as st
|
3 |
+
import os
|
4 |
+
import translator
|
5 |
+
from translate import Translator
|
6 |
+
|
7 |
+
st.title('Text To Speech')
|
8 |
+
|
9 |
+
lang_options = {
|
10 |
+
'Turkish': 'tr',
|
11 |
+
'English': 'en',
|
12 |
+
'German': 'de',
|
13 |
+
'French': 'fr',
|
14 |
+
'Spanish': 'es'
|
15 |
+
}
|
16 |
+
|
17 |
+
input_language=st.selectbox("Your txt language:", list(lang_options.keys()))
|
18 |
+
lang_input=lang_options[input_language]
|
19 |
+
selected_lang = st.selectbox("Language to be vocalized:", list(lang_options.keys()))
|
20 |
+
lang = lang_options[selected_lang]
|
21 |
+
|
22 |
+
uploaded_file = st.file_uploader("Upload.txt file:", type=["txt"])
|
23 |
+
|
24 |
+
|
25 |
+
#translator = Translator(from_lang=lang_input, to_lang=lang)
|
26 |
+
#translated_text = translator.translate(text, src=lang_input, dest=lang_out).text
|
27 |
+
#translated_text = translator.translate(text)
|
28 |
+
#st.write(f"Çevrilen metin ({text}):\n{translated_text}")
|
29 |
+
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
text = uploaded_file.read().decode('utf-8')
|
33 |
+
st.write(f"Text:\n{text}")
|
34 |
+
translator = Translator(from_lang=lang_input, to_lang=lang)
|
35 |
+
#translated_text = translator.translate(text, src=lang_input, dest=lang_out).text
|
36 |
+
translated_text = translator.translate(text)
|
37 |
+
st.write(f"Translated Text:\n{translated_text}")
|
38 |
+
|
39 |
+
if st.button("Create"):
|
40 |
+
try:
|
41 |
+
save_it = gTTS(text=translated_text, lang=lang, slow=False)
|
42 |
+
output_filename = str(text[:5]) + '.mp3'
|
43 |
+
save_it.save(output_filename)
|
44 |
+
st.success(f"Here is your file: {output_filename}")
|
45 |
+
|
46 |
+
|
47 |
+
with open(output_filename, "rb") as file:
|
48 |
+
st.download_button(
|
49 |
+
label="Download",
|
50 |
+
data=file,
|
51 |
+
file_name=output_filename,
|
52 |
+
mime="audio/mpeg",
|
53 |
+
)
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
except Exception as e:
|
59 |
+
st.error("Error.")
|
60 |
+
print("Hata:", e)
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
gtts
|
3 |
+
translator
|
4 |
+
googletrans==4.0.0rc1
|
5 |
+
translate
|