Update app.py
Browse files
app.py
CHANGED
@@ -12,17 +12,21 @@ st.title("Audio Analysis Pipeline")
|
|
12 |
|
13 |
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a", "mp4a"])
|
14 |
|
15 |
-
def
|
|
|
16 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as out_wav:
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
return out_wav.name
|
20 |
|
21 |
if uploaded_file:
|
22 |
st.audio(uploaded_file, format="audio/wav")
|
23 |
|
24 |
-
with st.spinner("
|
25 |
-
tmp_path =
|
26 |
|
27 |
try:
|
28 |
st.subheader("1️⃣ Noise Removal")
|
@@ -31,7 +35,7 @@ if uploaded_file:
|
|
31 |
remove_noise(tmp_path, denoised_path)
|
32 |
st.audio(denoised_path, format="audio/wav")
|
33 |
except Exception as e:
|
34 |
-
st.error(f"Noise removal failed: {e}")
|
35 |
|
36 |
try:
|
37 |
st.subheader("2️⃣ Speech Segmentation")
|
@@ -42,7 +46,7 @@ if uploaded_file:
|
|
42 |
for i, (start, end) in enumerate(segments[:5]):
|
43 |
st.write(f"Segment {i+1}: {start:.2f}s to {end:.2f}s")
|
44 |
except Exception as e:
|
45 |
-
st.error(f"VAD failed: {e}")
|
46 |
|
47 |
try:
|
48 |
st.subheader("3️⃣ Speaker Diarization")
|
@@ -58,7 +62,7 @@ if uploaded_file:
|
|
58 |
st.subheader("4️⃣ Noise Classification")
|
59 |
with st.spinner("Classifying background noise..."):
|
60 |
noise_predictions = classify_noise(denoised_path)
|
61 |
-
st.write("
|
62 |
for cls, prob in noise_predictions:
|
63 |
st.write(f"{cls}: {prob:.2f}")
|
64 |
except Exception as e:
|
|
|
12 |
|
13 |
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a", "mp4a"])
|
14 |
|
15 |
+
def prepare_audio(uploaded_file):
|
16 |
+
file_ext = uploaded_file.name.split('.')[-1].lower()
|
17 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as out_wav:
|
18 |
+
if file_ext == "wav":
|
19 |
+
out_wav.write(uploaded_file.read())
|
20 |
+
else:
|
21 |
+
audio = AudioSegment.from_file(uploaded_file, format=file_ext)
|
22 |
+
audio.export(out_wav.name, format="wav")
|
23 |
return out_wav.name
|
24 |
|
25 |
if uploaded_file:
|
26 |
st.audio(uploaded_file, format="audio/wav")
|
27 |
|
28 |
+
with st.spinner("🔄 Preparing audio..."):
|
29 |
+
tmp_path = prepare_audio(uploaded_file)
|
30 |
|
31 |
try:
|
32 |
st.subheader("1️⃣ Noise Removal")
|
|
|
35 |
remove_noise(tmp_path, denoised_path)
|
36 |
st.audio(denoised_path, format="audio/wav")
|
37 |
except Exception as e:
|
38 |
+
st.error(f" Noise removal failed: {e}")
|
39 |
|
40 |
try:
|
41 |
st.subheader("2️⃣ Speech Segmentation")
|
|
|
46 |
for i, (start, end) in enumerate(segments[:5]):
|
47 |
st.write(f"Segment {i+1}: {start:.2f}s to {end:.2f}s")
|
48 |
except Exception as e:
|
49 |
+
st.error(f" VAD failed: {e}")
|
50 |
|
51 |
try:
|
52 |
st.subheader("3️⃣ Speaker Diarization")
|
|
|
62 |
st.subheader("4️⃣ Noise Classification")
|
63 |
with st.spinner("Classifying background noise..."):
|
64 |
noise_predictions = classify_noise(denoised_path)
|
65 |
+
st.write("Top predicted noise classes:")
|
66 |
for cls, prob in noise_predictions:
|
67 |
st.write(f"{cls}: {prob:.2f}")
|
68 |
except Exception as e:
|