|
from deep_translator import GoogleTranslator |
|
import streamlit as st |
|
from gtts import gTTS |
|
import tempfile |
|
|
|
|
|
st.title("Multilingual Text-to-Speech Converter") |
|
|
|
|
|
text_input = st.text_area("Enter the text you want to convert to speech:") |
|
|
|
|
|
language_options = {"English": "en", "Hindi": "hi", "Spanish": "es", "French": "fr", "German": "de"} |
|
selected_language = st.selectbox("Select output language", options=language_options.keys()) |
|
selected_lang_code = language_options[selected_language] |
|
|
|
|
|
if st.button("Convert to Speech"): |
|
if text_input.strip() == "": |
|
st.warning("Please enter some text.") |
|
else: |
|
|
|
translator = GoogleTranslator(source='auto', target=selected_lang_code) |
|
translated_text = translator.translate(text_input) |
|
|
|
|
|
tts = gTTS(text=translated_text, lang=selected_lang_code, slow=False) |
|
|
|
|
|
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file: |
|
tts.save(tmp_file.name) |
|
audio_file_path = tmp_file.name |
|
|
|
|
|
st.audio(audio_file_path, format="audio/mp3") |
|
|
|
|
|
st.success("Speech synthesis complete!") |
|
with open(audio_file_path, "rb") as file: |
|
st.download_button(label="Download MP3", data=file, file_name="translated_speech_output.mp3", mime="audio/mp3") |
|
|