feat(helpers): add sync_audio.py for precise multicam audio sync via GCC-PHAT#69
Open
robertgenito wants to merge 1 commit into
Open
feat(helpers): add sync_audio.py for precise multicam audio sync via GCC-PHAT#69robertgenito wants to merge 1 commit into
robertgenito wants to merge 1 commit into
Conversation
…GCC-PHAT Multicam projects need frame-accurate audio alignment. Eyeballing offsets from Scribe's (claps) audio_event timestamps drifts 200-500ms, and plain cross-correlation between mismatched mics gives a broad, ambiguous peak. GCC-PHAT whitens the cross-power spectrum before correlating, so the peak stays sharp regardless of mic frequency response or room reverb. It is sub-frame accurate even between a studio mic and an on-camera mic. The helper takes a reference video, one or more targets, and rough sync timestamps for at least one shared transient (a clap). It cross-correlates 10s+ windows around each event, combines the lag with the window-start delta into a precise source-time offset, averages across events per target, and flags disagreement over 50ms as likely clap-pattern aliasing or clock drift. Output goes to sync_offsets.json, the helper is documented in SKILL.md, and scipy is declared as a direct dependency. More about me: https://geni.to/about Signed-off-by: Robert Genito <robert@robertgenito.com>
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="helpers/sync_audio.py">
<violation number="1" location="helpers/sync_audio.py:197">
P2: Default reference name "REF" is inconsistent with the docstring example and help text, causing events to be silently skipped when users follow the documented CLI pattern.</violation>
<violation number="2" location="helpers/sync_audio.py:270">
P2: Target measurement coverage is not validated: if a target has no shared events, the script silently produces partial JSON output and exits 0.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| print("=" * 60) | ||
| for cam, ms in by_target.items(): | ||
| if not ms: | ||
| print(f" {cam}: no measurements") |
There was a problem hiding this comment.
P2: Target measurement coverage is not validated: if a target has no shared events, the script silently produces partial JSON output and exits 0.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers/sync_audio.py, line 270:
<comment>Target measurement coverage is not validated: if a target has no shared events, the script silently produces partial JSON output and exits 0.</comment>
<file context>
@@ -0,0 +1,295 @@
+ print("=" * 60)
+ for cam, ms in by_target.items():
+ if not ms:
+ print(f" {cam}: no measurements")
+ continue
+ offsets = [m["precise_offset"] for m in ms]
</file context>
| if not (args.reference and args.target and args.event): | ||
| sys.exit("Need --config OR (--reference + --target + --event …)") | ||
|
|
||
| ref_name, ref_path = args.reference.split("=", 1) if "=" in args.reference else ("REF", args.reference) |
There was a problem hiding this comment.
P2: Default reference name "REF" is inconsistent with the docstring example and help text, causing events to be silently skipped when users follow the documented CLI pattern.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers/sync_audio.py, line 197:
<comment>Default reference name "REF" is inconsistent with the docstring example and help text, causing events to be silently skipped when users follow the documented CLI pattern.</comment>
<file context>
@@ -0,0 +1,295 @@
+ if not (args.reference and args.target and args.event):
+ sys.exit("Need --config OR (--reference + --target + --event …)")
+
+ ref_name, ref_path = args.reference.split("=", 1) if "=" in args.reference else ("REF", args.reference)
+ targets = {}
+ for t in args.target:
</file context>
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.
What
Adds
helpers/sync_audio.py, a precise multicam audio-sync helper, documents it inSKILL.md, and declaresscipyas a direct dependency.Why
Multicam projects need frame-accurate audio alignment. Eyeballing offsets from Scribe's
(claps)audio_event timestamps drifts 200-500ms, and plain cross-correlation between mismatched microphones gives a broad, ambiguous peak. GCC-PHAT (Generalized Cross-Correlation with Phase Transform) whitens the cross-power spectrum before correlating, so the peak stays sharp regardless of mic frequency response or room reverb. It is sub-frame accurate even between a studio mic and an on-camera mic.How it works
sync_offsets.jsonwithfinaloffsets per target plus per-event measurements.Usage
Dependencies
Declares
scipyinpyproject.toml. It was already present transitively (vialibrosa), but this helper importsscipy.signalandscipy.io.wavfiledirectly, so it should be an explicit dependency.Summary by cubic
Adds
helpers/sync_audio.pyto precisely sync multicam audio using GCC-PHAT. Produces sub-frame accurate offsets across dissimilar mics and writessync_offsets.json.New Features
SKILL.md.Dependencies
scipyas a direct dependency (used viascipy.signalandscipy.io.wavfile).Written for commit 6df055a. Summary will update on new commits.