Update app.py
Browse files
app.py
CHANGED
|
@@ -21,8 +21,31 @@ if st.button("Generate Audio"):
|
|
| 21 |
|
| 22 |
# Check if file exists
|
| 23 |
if os.path.exists(audio_file):
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
st.success("Audio generated successfully!")
|
| 27 |
|
| 28 |
# Provide download option
|
|
@@ -37,5 +60,3 @@ if st.button("Generate Audio"):
|
|
| 37 |
st.error("Audio file could not be generated.")
|
| 38 |
except Exception as e:
|
| 39 |
st.error(f"An error occurred: {e}")
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 21 |
|
| 22 |
# Check if file exists
|
| 23 |
if os.path.exists(audio_file):
|
| 24 |
+
# JavaScript-based audio player with speed adjustment
|
| 25 |
+
audio_data = open(audio_file, "rb").read()
|
| 26 |
+
audio_base64 = f"data:audio/wav;base64,{st.base64.b64encode(audio_data).decode()}"
|
| 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>
|
| 35 |
+
<label for="speed">Playback Speed: </label>
|
| 36 |
+
<input type="range" id="speed" min="0.5" max="2.0" value="1.0" step="0.1" onchange="document.getElementById('audio').playbackRate = this.value;">
|
| 37 |
+
<span id="speed-value">1.0x</span>
|
| 38 |
+
<script>
|
| 39 |
+
const speedSlider = document.getElementById("speed");
|
| 40 |
+
const speedValue = document.getElementById("speed-value");
|
| 41 |
+
speedSlider.addEventListener("input", () => {{
|
| 42 |
+
speedValue.textContent = speedSlider.value + "x";
|
| 43 |
+
}});
|
| 44 |
+
</script>
|
| 45 |
+
""",
|
| 46 |
+
unsafe_allow_html=True,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
st.success("Audio generated successfully!")
|
| 50 |
|
| 51 |
# Provide download option
|
|
|
|
| 60 |
st.error("Audio file could not be generated.")
|
| 61 |
except Exception as e:
|
| 62 |
st.error(f"An error occurred: {e}")
|
|
|
|
|
|