|
|
|
|
|
import streamlit as st |
|
|
from gtts import gTTS |
|
|
import os |
|
|
|
|
|
|
|
|
def text_to_speech(text, lang='en', tld='com'): |
|
|
|
|
|
if lang == 'ko': |
|
|
tts = gTTS(text, lang='ko') |
|
|
else: |
|
|
tts = gTTS(text, lang=lang, tld=tld) |
|
|
audio_file = 'output.mp3' |
|
|
tts.save(audio_file) |
|
|
return audio_file |
|
|
|
|
|
|
|
|
def main(): |
|
|
st.title("Text-to-Speech Converter") |
|
|
|
|
|
|
|
|
user_input = st.text_area("Enter the text you want to convert to speech:", "Hello World") |
|
|
|
|
|
|
|
|
language = st.selectbox("Choose Language", options=['en', 'ko'], format_func=lambda x: 'English' if x == 'en' else 'Korean') |
|
|
|
|
|
|
|
|
if language == 'en': |
|
|
tld = st.selectbox("Choose Accent", options=[('AmE', 'com'), ('BrE', 'co.uk')], format_func=lambda x: x[0]) |
|
|
tld = tld[1] |
|
|
else: |
|
|
tld = 'none' |
|
|
|
|
|
|
|
|
if st.button("Convert"): |
|
|
audio_path = text_to_speech(user_input, lang=language, tld=tld) |
|
|
audio_file = open(audio_path, 'rb') |
|
|
audio_bytes = audio_file.read() |
|
|
st.audio(audio_bytes, format='audio/mp3') |
|
|
|
|
|
if __name__ == '__main__': |
|
|
main() |
|
|
|