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(music-video): keep lyric wav slices inside the decoded buffer (#9074)

[._.]/ Adam Eivy813caea84217
diff --git a/client/src/components/musicVideo/LyricsPanel.jsx b/client/src/components/musicVideo/LyricsPanel.jsx
index 2bda2f3951..e2ce39dbcc 100644
--- a/client/src/components/musicVideo/LyricsPanel.jsx
+++ b/client/src/components/musicVideo/LyricsPanel.jsx
@@ -72,6 +72,7 @@ function WordTimingRow({ cue, onPreview, onCommit }) {
drag.current = null;
onCommit(nudgeWordBoundary(base, index, delta));
}}
+ onPointerCancel={() => { drag.current = null; }}
/>
<button type="button" aria-label={`Nudge the end of ${word.w} later`}
onClick={() => onCommit(nudgeWordBoundary(words, index, 0.05))}
@@ -235,6 +236,8 @@ export default function LyricsPanel({ project, onEditLocal, onSave, onImport, im
<input type="text" maxLength={500} aria-label={`Line ${i + 1} text`}
value={cue.text} onChange={(e) => {
const text = e.target.value;
+ // Omit words. null would fail the cue schema, and a whole-list
+ // save without the key drops timings that no longer match the text.
editCue(cue.id, cue.words && text !== cue.text ? { text, words: undefined } : { text });
}}
onBlur={() => saveCues()} className={`${inputCls} min-w-0 flex-1 basis-40`} />
diff --git a/server/services/musicVideo/lyricAlign.js b/server/services/musicVideo/lyricAlign.js
index 7cd04a3a90..27c58fe599 100644
--- a/server/services/musicVideo/lyricAlign.js
+++ b/server/services/musicVideo/lyricAlign.js
@@ -355,11 +355,15 @@ export function wavDurationSec(buf) {
export function sliceWav(buf, startSec, endSec) {
const info = wavInfo(buf);
- if (!info) throw new ServerError('Decoded audio was not a PCM WAV.', { status: 422, code: 'LYRIC_ALIGN_DECODE_FAILED' });
+ if (!info || info.blockAlign !== 2) {
+ throw new ServerError('Decoded audio was not 16-bit mono PCM.', { status: 422, code: 'LYRIC_ALIGN_DECODE_FAILED' });
+ }
const start = Math.max(0, Math.min(info.sampleCount, Math.round(startSec * info.sampleRate)));
const end = Math.max(start, Math.min(info.sampleCount, Math.round(endSec * info.sampleRate)));
const out = encodePcm16Wav(end - start, info.sampleRate);
- buf.copy(out, 44, info.dataOffset + start * info.blockAlign, info.dataOffset + end * info.blockAlign);
+ const byteStart = info.dataOffset + start * info.blockAlign;
+ const byteEnd = Math.min(buf.length, info.dataOffset + end * info.blockAlign);
+ buf.copy(out, 44, byteStart, byteEnd);
return out;
}
diff --git a/server/services/musicVideo/lyricAlign.test.js b/server/services/musicVideo/lyricAlign.test.js
index f48e0f0014..b697a8abfd 100644
--- a/server/services/musicVideo/lyricAlign.test.js
+++ b/server/services/musicVideo/lyricAlign.test.js
@@ -137,6 +137,12 @@ describe('lyric alignment audio', () => {
const wav = encodePcm16Wav(16000 * 4);
expect(wavDurationSec(wav)).toBeCloseTo(4, 3);
expect(wavDurationSec(sliceWav(wav, 1, 2.5))).toBeCloseTo(1.5, 3);
+ const truncated = encodePcm16Wav(16000);
+ truncated.writeUInt32LE(999999, 40);
+ expect(wavDurationSec(sliceWav(truncated, 0, 2))).toBeCloseTo(1, 3);
+ const stereo = encodePcm16Wav(100);
+ stereo.writeUInt16LE(4, 32);
+ expect(() => sliceWav(stereo, 0, 0.01)).toThrow(/16-bit mono/);
});
it('uses the vocal stem when one is attached, and does not fall back when that file is missing', async () => {