Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# Streamlit app UI
|
| 6 |
st.title("Text-to-Audio App")
|
|
@@ -21,14 +22,16 @@ if st.button("Generate Audio"):
|
|
| 21 |
|
| 22 |
# Check if file exists
|
| 23 |
if os.path.exists(audio_file):
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
|
|
|
| 28 |
st.markdown(
|
| 29 |
f"""
|
| 30 |
<audio id="audio" controls>
|
| 31 |
-
<source src="{audio_base64}" type="audio/wav">
|
| 32 |
Your browser does not support the audio element.
|
| 33 |
</audio>
|
| 34 |
<br>
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
| 4 |
+
import base64 # Import Python's base64 module
|
| 5 |
|
| 6 |
# Streamlit app UI
|
| 7 |
st.title("Text-to-Audio App")
|
|
|
|
| 22 |
|
| 23 |
# Check if file exists
|
| 24 |
if os.path.exists(audio_file):
|
| 25 |
+
# Encode audio file to base64
|
| 26 |
+
with open(audio_file, "rb") as f:
|
| 27 |
+
audio_data = f.read()
|
| 28 |
+
audio_base64 = base64.b64encode(audio_data).decode()
|
| 29 |
|
| 30 |
+
# JavaScript-based audio player with speed adjustment
|
| 31 |
st.markdown(
|
| 32 |
f"""
|
| 33 |
<audio id="audio" controls>
|
| 34 |
+
<source src="data:audio/wav;base64,{audio_base64}" type="audio/wav">
|
| 35 |
Your browser does not support the audio element.
|
| 36 |
</audio>
|
| 37 |
<br>
|