Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,58 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
from utils.
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
st.
|
| 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 |
-
st.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tempfile
|
| 3 |
+
from utils.noise_removal import remove_noise
|
| 4 |
+
from utils.vad_segmentation import vad_segmentation
|
| 5 |
+
from utils.speaker_diarization import diarize_speakers
|
| 6 |
+
from utils.noise_classification import classify_noise
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Audio Analyzer", layout="wide")
|
| 9 |
+
st.title(" Audio Analysis Pipeline")
|
| 10 |
+
|
| 11 |
+
uploaded_file = st.file_uploader("📤 Upload an audio file", type=["wav", "mp3"])
|
| 12 |
+
|
| 13 |
+
if uploaded_file:
|
| 14 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 15 |
+
tmp.write(uploaded_file.read())
|
| 16 |
+
tmp_path = tmp.name
|
| 17 |
+
|
| 18 |
+
st.audio(tmp_path, format='audio/wav')
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
st.subheader("1️⃣ Noise Removal")
|
| 22 |
+
denoised_path = tmp_path.replace(".wav", "_denoised.wav")
|
| 23 |
+
with st.spinner("Removing noise..."):
|
| 24 |
+
remove_noise(tmp_path, denoised_path)
|
| 25 |
+
st.audio(denoised_path, format="audio/wav")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
st.error(f"Noise removal failed: {e}")
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
st.subheader("2️⃣ Speech Segmentation")
|
| 31 |
+
with st.spinner("Running Voice Activity Detection..."):
|
| 32 |
+
speech_annotation = vad_segmentation(denoised_path)
|
| 33 |
+
segments = [(seg.start, seg.end) for seg in speech_annotation.itersegments()]
|
| 34 |
+
st.write(f" Detected {len(segments)} speech segments.")
|
| 35 |
+
for i, (start, end) in enumerate(segments[:5]):
|
| 36 |
+
st.write(f"Segment {i+1}: {start:.2f}s to {end:.2f}s")
|
| 37 |
+
except Exception as e:
|
| 38 |
+
st.error(f"VAD failed: {e}")
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
st.subheader("3️⃣ Speaker Diarization")
|
| 42 |
+
with st.spinner("Diarizing speakers..."):
|
| 43 |
+
diarization = diarize_speakers(denoised_path)
|
| 44 |
+
st.text(" Speakers detected:")
|
| 45 |
+
for turn, _, speaker in diarization.itertracks(yield_label=True):
|
| 46 |
+
st.write(f"{turn.start:.2f}s - {turn.end:.2f}s: Speaker {speaker}")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
st.error(f"Speaker diarization failed: {e}")
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
st.subheader("4️⃣ Noise Classification")
|
| 52 |
+
with st.spinner("Classifying background noise..."):
|
| 53 |
+
noise_predictions = classify_noise(denoised_path)
|
| 54 |
+
st.write(" Top predicted noise classes:")
|
| 55 |
+
for cls, prob in noise_predictions:
|
| 56 |
+
st.write(f"{cls}: {prob:.2f}")
|
| 57 |
+
except Exception as e:
|
| 58 |
+
st.error(f"Noise classification failed: {e}")
|