Skip to content

Implement_sound_event_detection_module (Goal 1)#22

Open
Siddharth-732 wants to merge 1 commit into
PlanetRead:mainfrom
Siddharth-732:feat/implement-sound-event-detection-module
Open

Implement_sound_event_detection_module (Goal 1)#22
Siddharth-732 wants to merge 1 commit into
PlanetRead:mainfrom
Siddharth-732:feat/implement-sound-event-detection-module

Conversation

@Siddharth-732
Copy link
Copy Markdown

Summary

This PR implements the first phase of the Intelligent CC Suggestion Tool. The goal is to automatically identify meaningful non-speech audio events in videos to help editors focus on where closed captions (CC) are truly needed.

Key Features

  • AI Sound Classification: Integrates Google's YAMNet model to detect 521 different sound classes (e.g., Honking, Laughter, Music).
  • Intelligent Event Merging: Automatically merges overlapping sound detections into continuous events with accurate start/end timestamps.
  • Configurable Confidence: Uses a thresholding system (default 0.3) to minimize ambient noise "hallucinations."

Technical Implementation

  • cc_tool/audio/detector.py: Core logic for model loading and sliding-window inference.
  • cc_tool/audio/extractor.py: Portable subprocess wrapper for FFmpeg.
  • cc_tool/audio/models.py: Pydantic-style dataclasses for predictable data handling.
  • cc_tool/audio/utils.py: Waveform normalization and chunking utilities.

How to Verify

  • Prerequisites: Install FFmpeg (winget install ffmpeg).
  • Install: pip install -r requirements.txt.
  • Run Test:
    python test_goal_1.py "your_video.mp4"

ScreenShot of Results

Screenshot 2026-05-12 203035

Screenshot explanation - after the first test, the pipeline will create a output folder that will contain the audio of the video as sample.wav, this output will then be analyzed and the output can be seen in the terminal, i.e it detects 3 events.

Copilot AI review requested due to automatic review settings May 12, 2026 17:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the “Goal 1” sound event detection pipeline for the Intelligent CC Suggestion Tool, adding YAMNet-based audio event detection plus basic audio utilities, extraction, documentation, and initial tests.

Changes:

  • Added cc_tool.audio package: FFmpeg-based audio extraction, waveform chunking/normalization, YAMNet inference, and simple adjacent-event merging.
  • Added a manual run script (test_goal_1.py), README setup/usage guidance, and Python dependencies.
  • Added initial pytest suites for audio utilities/extractor, plus decision/export tests that currently reference missing modules.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cc_tool/audio/detector.py Implements YAMNet loading, inference over chunks, and event merging.
cc_tool/audio/extractor.py Adds FFmpeg subprocess wrapper for extracting 16kHz mono WAV.
cc_tool/audio/models.py Adds AudioEvent dataclass and serialization helper.
cc_tool/audio/utils.py Adds chunking and waveform normalization helpers.
cc_tool/audio/__init__.py Exposes audio API via package exports.
cc_tool/__init__.py Marks cc_tool as a package.
tests/test_audio/test_detector.py Adds tests for chunking and normalization utilities.
tests/test_audio/test_extractor.py Adds a basic missing-input test for extractor.
tests/test_audio/__init__.py Marks audio tests as a package.
tests/test_decision/test_combiner.py Adds tests for a decision combiner that is not present in this PR/repo.
tests/test_decision/test_srt_writer.py Adds tests for an SRT writer/models that are not present in this PR/repo.
tests/test_decision/__init__.py Marks decision tests as a package.
test_goal_1.py Adds a manual run script, but is currently named like a pytest test module.
requirements.txt Adds TensorFlow/TFHub and other dependencies (includes currently-unused pydantic).
README.md Documents setup and example usage for Goal 1.
.gitignore Ignores Python artifacts, venvs, and outputs/ directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +8
from cc_tool.vision.models import ReactionResult
from cc_tool.decision.combiner import combine_and_decide


Comment on lines +5 to +8
from cc_tool.decision.models import CCAnnotation
from cc_tool.export.srt_writer import write_srt, _sec_to_srt_time


Comment thread test_goal_1.py
Comment on lines +1 to +7
from cc_tool.audio.extractor import extract_audio
from cc_tool.audio.detector import SoundEventDetector
import sys
import os

def test_goal_1(video_path):
print(f"Testing Goal 1 with: {video_path}")
Comment thread cc_tool/audio/utils.py
Comment on lines +3 to +17
def chunk_audio(waveform, sample_rate, window_sec=1.0, stride_sec=0.5):
"""Split audio into overlapping windows for YAMNet."""
window_samples = int(window_sec * sample_rate)
stride_samples = int(stride_sec * sample_rate)
total_samples = len(waveform)

chunks = []
start = 0
while start + window_samples <= total_samples:
end = start + window_samples
start_sec = start / sample_rate
end_sec = end / sample_rate
chunks.append((start_sec, end_sec, waveform[start:end]))
start += stride_samples
return chunks
Comment thread cc_tool/audio/utils.py
Comment on lines +19 to +25
def normalize_waveform(waveform):
"""Normalize audio to [-1.0, 1.0]."""
waveform = waveform.astype(np.float32)
max_val = np.max(np.abs(waveform))
if max_val > 0:
waveform = waveform / max_val
return waveform
Comment thread cc_tool/audio/detector.py
Comment on lines +40 to +47
def detect(self, wav_path):
self._load_model()
waveform, sr = sf.read(wav_path, dtype="float32")
if waveform.ndim > 1: waveform = waveform.mean(axis=1)
waveform = normalize_waveform(waveform)

chunks = chunk_audio(waveform, sr)
raw_events = []

if output_wav is None:
os.makedirs("outputs/audio", exist_ok=True)
output_wav = f"outputs/audio/{video_path.stem}.wav"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants