Spaces:
Sleeping
Sleeping
hanifekaptan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,39 @@
|
|
1 |
-
from gtts import gTTS
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
data
|
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 |
-
|
|
|
|
1 |
+
from gtts import gTTS
|
2 |
+
from gtts import lang
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
# Load language data from CSV file
|
7 |
+
data = lang.tts_langs()
|
8 |
+
|
9 |
+
st.title("Text to Speech")
|
10 |
+
text = st.text_area("Enter your text", placeholder="Enter your text here")
|
11 |
+
|
12 |
+
# Create a dropdown menu for language selection
|
13 |
+
language = st.selectbox("Select Language", data.values())
|
14 |
+
|
15 |
+
# Create a dropdown menu for speed selection
|
16 |
+
speed = st.selectbox("Select Language", ["Fast", "Slow"])
|
17 |
+
|
18 |
+
if st.button("Convert"):
|
19 |
+
try:
|
20 |
+
# Determine if the speech should be slow
|
21 |
+
is_slow = False if speed == "Fast" else True
|
22 |
+
|
23 |
+
# Get the selected language code
|
24 |
+
lang = [key for key, value in data.items() if value == language][0]
|
25 |
+
|
26 |
+
# Create a gTTS object with the provided text and language
|
27 |
+
tts = gTTS(text = text, lang = lang, slow = is_slow)
|
28 |
+
|
29 |
+
except Exception as e:
|
30 |
+
st.error("Could not be converted" + str(e))
|
31 |
+
|
32 |
+
try:
|
33 |
+
tts.save("output.mp3")
|
34 |
+
# Provide a download button for the user to download the MP3 file
|
35 |
+
with open("output.mp3", "rb") as f:
|
36 |
+
download = st.download_button("Download", data=f, file_name="output.mp3", mime="audio/mpeg")
|
37 |
+
|
38 |
+
except Exception as e:
|
39 |
+
st.error("Download could not be completed"+ str(e))
|