|
|
import streamlit as st |
|
|
from gtts import gTTS |
|
|
import pyttsx3 |
|
|
import os |
|
|
|
|
|
|
|
|
def gtts_text_to_speech(text): |
|
|
tts = gTTS(text=text, lang='en', slow=False) |
|
|
tts.save("output.mp3") |
|
|
return "output.mp3" |
|
|
|
|
|
|
|
|
def pyttsx3_text_to_speech(text): |
|
|
engine = pyttsx3.init() |
|
|
engine.save_to_file(text, "output.mp3") |
|
|
engine.runAndWait() |
|
|
return "output.mp3" |
|
|
|
|
|
|
|
|
st.title("Text-to-Speech Converter") |
|
|
|
|
|
|
|
|
user_input = st.text_area("Enter text:", "Hello, how can I assist you today?") |
|
|
|
|
|
|
|
|
tts_option = st.radio("Choose Text-to-Speech Method", ("Google TTS", "Offline TTS")) |
|
|
|
|
|
|
|
|
if st.button("Convert to Speech"): |
|
|
if tts_option == "Google TTS": |
|
|
output_file = gtts_text_to_speech(user_input) |
|
|
else: |
|
|
output_file = pyttsx3_text_to_speech(user_input) |
|
|
|
|
|
st.audio(output_file, format="audio/mp3") |
|
|
st.success("Speech generated successfully!") |
|
|
|