Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,18 @@
|
|
| 1 |
from gtts import gTTS
|
| 2 |
import streamlit as st
|
| 3 |
-
|
| 4 |
|
| 5 |
st.title('Text To Speech')
|
|
|
|
| 6 |
lang_options = {
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
input_language=st.selectbox("Lütfen metin dilini seçiniz", list(lang_options.keys()))
|
| 16 |
lang_input=lang_options[input_language]
|
| 17 |
selected_lang = st.selectbox("Lütfen ses dili seçiniz", list(lang_options.keys()))
|
|
@@ -19,20 +20,26 @@ lang = lang_options[selected_lang]
|
|
| 19 |
|
| 20 |
uploaded_file = st.file_uploader("Upload txt file", type=['txt'])
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def filetospeech(uploaded_file, lang_input=lang_input, slow=False):
|
| 24 |
metin = ""
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
if uploaded_file is not None:
|
| 38 |
-
filetospeech(uploaded_file)
|
|
|
|
| 1 |
from gtts import gTTS
|
| 2 |
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
st.title('Text To Speech')
|
| 6 |
+
|
| 7 |
lang_options = {
|
| 8 |
+
'Turkish': 'tr',
|
| 9 |
+
'English': 'en',
|
| 10 |
+
'German': 'de',
|
| 11 |
+
'French': 'fr',
|
| 12 |
+
'Spanish': 'es'
|
| 13 |
+
}
|
| 14 |
|
| 15 |
+
# Dil seçimi
|
| 16 |
input_language=st.selectbox("Lütfen metin dilini seçiniz", list(lang_options.keys()))
|
| 17 |
lang_input=lang_options[input_language]
|
| 18 |
selected_lang = st.selectbox("Lütfen ses dili seçiniz", list(lang_options.keys()))
|
|
|
|
| 20 |
|
| 21 |
uploaded_file = st.file_uploader("Upload txt file", type=['txt'])
|
| 22 |
|
| 23 |
+
def filetospeech(file_path, lang_input=lang_input, slow=False):
|
|
|
|
| 24 |
metin = ""
|
| 25 |
+
try:
|
| 26 |
+
if os.path.exists(file_path):
|
| 27 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 28 |
+
for line in file:
|
| 29 |
+
metin += line
|
| 30 |
+
st.write(metin)
|
| 31 |
+
|
| 32 |
+
if st.button("Create"):
|
| 33 |
+
kayit = gTTS(text=metin, lang=lang, slow=False)
|
| 34 |
+
dosya_adi = str(metin[:5]) + '.mp3'
|
| 35 |
+
kayit.save(dosya_adi)
|
| 36 |
+
st.success(f"Ses kaydedildi: {dosya_adi}")
|
| 37 |
+
return dosya_adi
|
| 38 |
+
else:
|
| 39 |
+
st.error("Dosya bulunamadı.")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error("Ses kaydedilmedi...")
|
| 42 |
+
print("Hata:", e)
|
| 43 |
|
| 44 |
if uploaded_file is not None:
|
| 45 |
+
filetospeech(uploaded_file.name)
|