Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep lyric onset snaps inside director-set windows (#9255)

Adam Eivydd2dae214087
diff --git a/server/services/musicVideo/lyricAlignCore.js b/server/services/musicVideo/lyricAlignCore.js
index 52a376e092..16b3119791 100644
--- a/server/services/musicVideo/lyricAlignCore.js
+++ b/server/services/musicVideo/lyricAlignCore.js
@@ -533,7 +533,11 @@ function alignDirectorWords(cues, recognizedWords, { phraseAnchored = false } =
delete cleared.words;
return cleared;
}
- if (!phraseAnchored) return applyWordTimes(cue, words);
+ if (!phraseAnchored) {
+ const aligned = applyWordTimes(cue, words);
+ delete aligned.matched;
+ return aligned;
+ }
const matched = words.filter((word) => word.conf === 'matched').length / words.length;
// A weak recognition must not overwrite even an untimed line with invented
// timing. Keep its previous word boundaries too, if any.
@@ -707,6 +711,10 @@ export function snapLineStarts(lines, onsets, originals = []) {
.sort((a, b) => Math.abs(a - first) - Math.abs(b - first))[0];
if (onset == null) return line;
const delta = onset - first;
+ // A snap is optional evidence, never permission to move karaoke words
+ // outside the line window the director explicitly set.
+ if (original.startSec != null && first + delta < original.startSec) return line;
+ if (original.endSec != null && line.words.at(-1).endSec + delta > original.endSec) return line;
return {
...line,
startSec: original.startSec ?? round3(onset),
diff --git a/server/services/musicVideo/lyricAlignCore.test.js b/server/services/musicVideo/lyricAlignCore.test.js
index 290eb89e68..ef3bfa88d6 100644
--- a/server/services/musicVideo/lyricAlignCore.test.js
+++ b/server/services/musicVideo/lyricAlignCore.test.js
@@ -60,6 +60,18 @@ describe('phrase lyric matching', () => {
expect(line.words[3].startSec).toBeCloseTo(1.6);
});
+ it('skips a snap that would cross either authored line boundary', () => {
+ const cues = [
+ { text: 'hello morning', startSec: 2, endSec: 3 },
+ { text: 'quiet evening', startSec: 5, endSec: 5.8 },
+ ];
+ const recognized = [...words('hello morning', 2.1), ...words('quiet evening', 5.1)];
+ const aligned = alignDirectorWords(cues, recognized, { phraseAnchored: true });
+ expect(snapLineStarts(aligned, [1.9, 5.3], cues)).toEqual(aligned);
+ const [fallback] = alignDirectorWords([{ ...cues[0], matched: 0.2 }], words('hello morning', 2.1));
+ expect(fallback.matched).toBeUndefined();
+ });
+
it('preserves low-confidence prior times and words, while snapping confident words together and honoring authored sides', () => {
const cues = [
{ text: 'hello morning', startSec: null, endSec: null },