File size: 1,911 Bytes
21913c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from gtts import gTTS
import streamlit as st
import os
import translator
from translate import Translator

st.title('Text To Speech')

lang_options = {
    'Turkish': 'tr',
    'English': 'en',
    'German': 'de',
    'French': 'fr',
    'Spanish': 'es'
}

input_language=st.selectbox("Your txt language:", list(lang_options.keys()))
lang_input=lang_options[input_language]
selected_lang = st.selectbox("Language to be vocalized:", list(lang_options.keys()))
lang = lang_options[selected_lang]

uploaded_file = st.file_uploader("Upload.txt file:", type=["txt"])


#translator = Translator(from_lang=lang_input, to_lang=lang)
#translated_text = translator.translate(text, src=lang_input, dest=lang_out).text
#translated_text = translator.translate(text)
#st.write(f"Çevrilen metin ({text}):\n{translated_text}")


if uploaded_file is not None:
    text = uploaded_file.read().decode('utf-8')
    st.write(f"Text:\n{text}")
    translator = Translator(from_lang=lang_input, to_lang=lang)
    #translated_text = translator.translate(text, src=lang_input, dest=lang_out).text
    translated_text = translator.translate(text)
    st.write(f"Translated Text:\n{translated_text}")

    if st.button("Create"):
        try:
            save_it = gTTS(text=translated_text, lang=lang, slow=False)
            output_filename = str(text[:5]) + '.mp3'
            save_it.save(output_filename)
            st.success(f"Here is your file: {output_filename}")

            
            with open(output_filename, "rb") as file:
                st.download_button(
                    label="Download",
                    data=file,
                    file_name=output_filename,
                    mime="audio/mpeg",
                )
            
            
                    
                
        except Exception as e:
            st.error("Error.")
            print("Hata:", e)