Implement_sound_event_detection_module (Goal 1)#22
Open
Siddharth-732 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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.audiopackage: 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 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 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 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 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Technical Implementation
How to Verify
python test_goal_1.py "your_video.mp4"ScreenShot of Results
Screenshot explanation - after the first test, the pipeline will create a
outputfolder that will contain the audio of the video assample.wav, this output will then be analyzed and the output can be seen in theterminal, i.e it detects 3 events.