hanifekaptan's picture
Upload 3 files
8e8c518 verified
raw
history blame
1.3 kB
from gtts import gTTS
import streamlit as st
import pandas as pd
# Load language data from CSV file
data = pd.read_csv("gtts_lang.csv")
st.title("Text to Speech")
text = st.text_area("Enter your text", placeholder="Enter your text here")
# Create a dropdown menu for language selection
language = st.selectbox("Select Language", data["Language"], index = 43)
# Create a dropdown menu for speed selection
speed = st.selectbox("Select Language", ["Fast", "Slow"], index=0)
if st.button("Convert"):
try:
# Determine if the speech should be slow
is_slow = False if speed == "Fast" else True
# Get the selected language code
lang = data[data["Language"] == language]["Lang"].values[0]
# Create a gTTS object with the provided text and language
tts = gTTS(text = text, lang = lang, slow = is_slow)
except Exception as e:
st.error("Dönüşüm hatası", e)
try:
tts.save("output.mp3")
# Provide a download button for the user to download the MP3 file
with open("output.mp3", "rb") as f:
download = st.download_button("Download", data=f, file_name="output.mp3", mime="audio/mpeg")
except Exception as e:
st.error("İndirme hatası", e)