Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +43 -18
src/streamlit_app.py
CHANGED
|
@@ -1,33 +1,58 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
# ---
|
| 5 |
try:
|
| 6 |
-
# This is the line that is currently crashing your app
|
| 7 |
import sounddevice as sd
|
|
|
|
| 8 |
AUDIO_RECORDER_AVAILABLE = True
|
| 9 |
except OSError as e:
|
| 10 |
-
|
| 11 |
-
st.warning(f"Audio recording hardware not found or library failed. Recording is disabled. Error: {e}")
|
| 12 |
AUDIO_RECORDER_AVAILABLE = False
|
| 13 |
except Exception as e:
|
| 14 |
-
st.warning(f"
|
| 15 |
AUDIO_RECORDER_AVAILABLE = False
|
| 16 |
|
| 17 |
-
# ... (rest of your script) ...
|
| 18 |
-
|
| 19 |
# ------------------ STREAMLIT UI ------------------
|
| 20 |
st.title("π£οΈ Jugaadu Audio Collector")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
# --- Conditionally show the recording UI based on the flag ---
|
| 25 |
if AUDIO_RECORDER_AVAILABLE:
|
| 26 |
-
duration = st.slider("ποΈ Select recording duration (seconds)", 5,
|
| 27 |
-
if st.button("π΄ Start Recording"
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# --- Try importing sounddevice ---
|
| 6 |
try:
|
|
|
|
| 7 |
import sounddevice as sd
|
| 8 |
+
from scipy.io.wavfile import write
|
| 9 |
AUDIO_RECORDER_AVAILABLE = True
|
| 10 |
except OSError as e:
|
| 11 |
+
st.warning(f"Audio recording library failed (likely missing PortAudio). Recording disabled.\n\nError: {e}")
|
|
|
|
| 12 |
AUDIO_RECORDER_AVAILABLE = False
|
| 13 |
except Exception as e:
|
| 14 |
+
st.warning(f"Unexpected error loading audio recorder: {e}")
|
| 15 |
AUDIO_RECORDER_AVAILABLE = False
|
| 16 |
|
|
|
|
|
|
|
| 17 |
# ------------------ STREAMLIT UI ------------------
|
| 18 |
st.title("π£οΈ Jugaadu Audio Collector")
|
| 19 |
+
st.markdown("""
|
| 20 |
+
This tool helps collect local voice inputs to build regional datasets.
|
| 21 |
+
If your system supports it, you can record directly. If not, you can upload `.wav`, `.mp3`, or `.m4a` files instead.
|
| 22 |
+
""")
|
| 23 |
|
| 24 |
+
# -------------- RECORD AUDIO ------------------
|
|
|
|
|
|
|
| 25 |
if AUDIO_RECORDER_AVAILABLE:
|
| 26 |
+
duration = st.slider("ποΈ Select recording duration (seconds)", 5, 60, 10)
|
| 27 |
+
if st.button("π΄ Start Recording"):
|
| 28 |
+
try:
|
| 29 |
+
st.info("Recording...")
|
| 30 |
+
fs = 44100 # Sample rate
|
| 31 |
+
recording = sd.rec(int(duration * fs), samplerate=fs, channels=1)
|
| 32 |
+
sd.wait() # Wait until recording is finished
|
| 33 |
+
|
| 34 |
+
# Save to temp file
|
| 35 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
| 36 |
+
write(tmpfile.name, fs, recording)
|
| 37 |
+
st.success("β
Recording complete!")
|
| 38 |
+
st.audio(tmpfile.name, format='audio/wav')
|
| 39 |
+
|
| 40 |
+
# If you want to save/upload, do it here
|
| 41 |
+
st.info(f"Saved to: `{tmpfile.name}`")
|
| 42 |
+
except Exception as e:
|
| 43 |
+
st.error(f"Recording failed: {e}")
|
| 44 |
else:
|
| 45 |
+
st.error("π΄ Audio recording is not supported in this environment.")
|
| 46 |
+
st.info("Try running this app on your local computer to enable recording.")
|
| 47 |
+
|
| 48 |
+
# -------------- UPLOAD FALLBACK ------------------
|
| 49 |
+
st.markdown("---")
|
| 50 |
+
st.subheader("π€ Or Upload Audio")
|
| 51 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a"])
|
| 52 |
+
|
| 53 |
+
if uploaded_file is not None:
|
| 54 |
+
st.success("β
File uploaded successfully!")
|
| 55 |
+
st.audio(uploaded_file, format='audio/wav')
|
| 56 |
+
# You can save to disk or process further here
|
| 57 |
+
# with open("some_path.wav", "wb") as f:
|
| 58 |
+
# f.write(uploaded_file.getbuffer())
|