reab5555 commited on
Commit
bf0f0e7
·
verified ·
1 Parent(s): 49cf612

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +23 -0
visualization.py CHANGED
@@ -15,6 +15,8 @@ from matplotlib.patches import Rectangle
15
  from utils import seconds_to_timecode
16
  from anomaly_detection import determine_anomalies
17
  from scipy import interpolate
 
 
18
  import gradio as gr
19
  import os
20
 
@@ -256,3 +258,24 @@ def plot_stacked_mse_heatmaps(mse_face, mse_posture, mse_voice, df, title="Combi
256
  plt.tight_layout()
257
  plt.close()
258
  return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  from utils import seconds_to_timecode
16
  from anomaly_detection import determine_anomalies
17
  from scipy import interpolate
18
+ import librosa
19
+ import librosa.display
20
  import gradio as gr
21
  import os
22
 
 
258
  plt.tight_layout()
259
  plt.close()
260
  return fig
261
+
262
+ def plot_audio_waveform(audio_path, title="Audio Waveform"):
263
+ # Load the audio file
264
+ y, sr = librosa.load(audio_path)
265
+
266
+ # Create the plot
267
+ plt.figure(figsize=(20, 4))
268
+ librosa.display.waveshow(y, sr=sr)
269
+
270
+ # Set the x-axis to display timecodes
271
+ max_time = librosa.get_duration(y=y, sr=sr)
272
+ x_ticks = np.arange(0, max_time, max_time/10) # 10 ticks
273
+ x_labels = [f"{int(t//3600):02d}:{int((t%3600)//60):02d}:{int(t%60):02d}" for t in x_ticks]
274
+ plt.xticks(x_ticks, x_labels, rotation=45)
275
+
276
+ plt.title(title)
277
+ plt.xlabel("Time")
278
+ plt.ylabel("Amplitude")
279
+ plt.tight_layout()
280
+
281
+ return plt.gcf()