reab5555 commited on
Commit
7c9a942
·
verified ·
1 Parent(s): 2d9c135

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +26 -23
video_processing.py CHANGED
@@ -166,29 +166,32 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
166
  audio_path = os.path.join(temp_dir, "audio.wav")
167
  video.export(audio_path, format="wav")
168
 
169
- try:
170
- # Process audio
171
- most_frequent_voice, voice_features, voice_clusters = process_audio(audio_path)
172
-
173
- # Perform anomaly detection on voice
174
- X_voice = np.array(most_frequent_voice)
175
- mse_voice = anomaly_detection(X_voice, X_voice) # Using the same function as for facial features
176
-
177
- # Generate plots for voice
178
- mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
179
- color='green',
180
- anomaly_threshold=anomaly_threshold)
181
- mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
182
- anomaly_threshold, color='green')
183
- mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
184
- except Exception as e:
185
- print(f"Error in voice processing: {str(e)}")
186
- mse_voice = None
187
- mse_plot_voice = None
188
- mse_histogram_voice = None
189
- mse_heatmap_voice = None
190
- anomaly_segments_voice = None
191
-
 
 
 
192
 
193
 
194
  progress(0.95, "Generating plots")
 
166
  audio_path = os.path.join(temp_dir, "audio.wav")
167
  video.export(audio_path, format="wav")
168
 
169
+ try:
170
+ # Process audio
171
+ most_frequent_voice, voice_features, voice_clusters = process_audio(audio_path)
172
+
173
+ if len(voice_features) < 2:
174
+ print("Not enough voice segments for processing. Skipping voice analysis.")
175
+ raise ValueError("Insufficient voice data")
176
+
177
+ # Perform anomaly detection on voice
178
+ X_voice = np.array(most_frequent_voice)
179
+ mse_voice = anomaly_detection(X_voice, X_voice)
180
+
181
+ # Generate plots for voice
182
+ mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
183
+ color='green',
184
+ anomaly_threshold=anomaly_threshold)
185
+ mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
186
+ anomaly_threshold, color='green')
187
+ mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
188
+ except Exception as e:
189
+ print(f"Error in voice processing: {str(e)}")
190
+ mse_voice = None
191
+ mse_plot_voice = None
192
+ mse_histogram_voice = None
193
+ mse_heatmap_voice = None
194
+ anomaly_segments_voice = None
195
 
196
 
197
  progress(0.95, "Generating plots")