SKILL.md
Multimodal Fusion for Speaker Diarization
Overview
When working with video files, you can significantly improve speaker diarization by combining audio features with visual features like face detection and lip movement analysis.
When to Use
- Processing video files (not just audio)
- Multiple speakers visible on screen
- Need to disambiguate speakers with similar voices
- Improve accuracy by leveraging visual cues
Visual Feature Extraction
Face Detection
import cv2
import numpy as np
# Initialize face detector
face_cascade = cv2.CascadeClassifier(
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
)
# Process video frames
cap = cv2.VideoCapture(video_path)
fps = cap.get(cv2.CAP_PROP_FPS)
faces_by_time = {}
frame_count = 0
frame_skip = max(1, int(fps / 2)) # Process every other frame
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
if frame_count % frame_skip == 0:
timestamp = frame_count / fps
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
faces_by_time[timestamp] = len(faces)
frame_count += 1
cap.release()
Lip Movement Detection
lip_movement_by_time = {}
prev_mouth_roi = None
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
if frame_count % frame_skip == 0:
timestamp = frame_count / fps
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
lip_moving = False
for (x, y, w, h) in faces:
# Extract mouth region (lower 40% of face)
mouth_roi_y = y + int(h * 0.6)
mouth_roi_h = int(h * 0.4)
mouth_region = gray[mouth_roi_y:mouth_roi_y + mouth_roi_h, x:x + w]
if mouth_region.size > 0:
if prev_mouth_roi is not None and prev_mouth_roi.shape == mouth_region.shape:
# Calculate movement score
diff = cv2.absdiff(mouth_region, prev_mouth_roi)
movement_score = np.mean(diff)
if movement_score > 10: # Threshold for movement
lip_moving = True
prev_mouth_roi = mouth_region.copy()
break
lip_movement_by_time[timestamp] = lip_moving
frame_count += 1
