Skip to content

feat: preserve advanced lyric timing and vocal annotations - #266

Merged
1Lucas1apk merged 20 commits into
PerformanC:devfrom
SebasLoadJs:feat/advanced-lyrics
Nov 29, 2026
Merged

1Lucas1apk merged 20 commits into
PerformanC:devfrom
SebasLoadJs:feat/advanced-lyrics

Conversation

@SebasLoadJs

@SebasLoadJs SebasLoadJs commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Normalize provider-supplied line and token timing, and distinguish timed from unsynced lyrics.

  • Parse a bounded TTML subset for Unison, preserving voice agents, background vocals, sections, and explicit translations/romanization.

  • Preserve annotations in existing playback lyric event payloads and expose active line indices for overlapping vocals.

  • Ignore stale lyric responses after track changes or unsubscribe, and suppress timed events for unsynced lyrics.

  • Suppress timed playback events when provider timing is incomplete, and schedule expiry of overlapping background vocals.

Why

These changes allow clients to render richer synchronized lyrics while retaining the existing lyrics response and event structures. Timing and alternate text are preserved rather than generated.

Checkmarks

  • The modified endpoints have been tested.
  • Used the same indentation as the rest of the project.
  • Still compatible with LavaLink clients.

Additional information

Updated against upstream dev at 86c6a00. The README is unchanged from upstream. Formatting, type-check, build and regression tests passed on the earlier commit 944cd7c (fork CI job).

Runtime Passed Failed Skipped
Node.js 22 34 0 3
Node.js 24 34 0 3
Bun 32 0 —

The five Node HTTP adapter tests run on Node, not Bun. A separate native Bun server suite runs in Bun. These are fork CI results, not independent maintainer validation.

The earlier revision 13c12ad removed the review-requested test files without production changes. No new test files or workflow remain in the PR.

Earlier exact-HEAD fork validation passed on 13c12ad: type-check, build, generated-output verification and clean-checkout verification. Node.js 22 and 24 each passed 34 tests (0 failures, 3 skipped); Bun passed 32 tests (0 failures). Regression harnesses were restored only into a temporary directory outside the checkout, not into the submission. The earlier results above remain historical. These are contributor-fork checks, not independent maintainer validation.

Earlier review fix (e839473): Resolve nested parallel TTML begin/end relative to their parent, propagate applicable end bounds, and support duration limits for nested lines and words. Explicit iTunes Word/Line timing remains media-absolute. The previous 5-second result for a paragraph beginning at 5 seconds inside a 10-second container now resolves to 15 seconds. Fourteen isolated JavaScript assertions (including the previous-revision reproduction) passed outside the repository. Earlier exact-HEAD fork validation passed type-check, build, compiled-output and clean-checkout checks. Node 22 and 24 each passed 34 tests (3 skipped); Bun passed 32; zero failures. The new focused assertions were separate from these restored historical regression suites. No test file, workflow, or README changes are included in the PR.

Latest review fix (0c0c8ff): Accept Unison's bare seconds consistently in begin, end, and dur, preserving explicit units, clock syntax, and the nested relative timing fix. The complete official amazing-grace.ttml fixture now returns 16 synchronized lines and 98 timed words (previous revision returned 4 lines). All 15 TTML fixtures at Unison revision 5521c80 were downloaded into a temporary directory outside the checkout and verified against their Git blob hashes. Both 90210 revisions and all 12 intentionally malformed fixtures produced identical output to the previous revision; this is a regression comparison, not full XML conformance or malformed-document repair. Source and generated JavaScript outputs matched for all fixtures. Current exact-HEAD fork CI passed type-check, build, generated-output verification, historical harness (Node 22/24: 34 passed, 3 skipped each; Bun: 32 passed; no failures), focused timing assertions, official fixture audit, and clean-checkout verification. No test files or workflows were added to the PR.

Validation limitations: The parser covers a bounded parallel/absolute-time TTML subset, not the entire TTML standard. Live provider translations/romanization, synchronized Discord playback and end-to-end client compatibility were not verified.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

All Contributors have signed the CLA. The PR is now allowed to be merged.
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor Author

recheck

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed the current diff against the repository's explicit contribution constraints. The implementation itself is not the reason for this request: the PR adds committed test files (and, in #270, a dedicated regression workflow) despite NodeLink having no authorized test structure or test infrastructure. Please remove the listed files from the PR rather than relocating them into a new test directory or adding a runner. I have not changed your branch or created commits. Build, type-check and runtime validation were not independently executed here; this review is limited to the clear repository-structure requirement.

Comment thread src/modules/playbackLyrics.test.ts Outdated
@@ -0,0 +1,79 @@
import assert from 'node:assert/strict'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this newly added test file. NodeLink has no authorized/versioned test structure; adding tests under src/modules is not permitted. Keep any local reproduction outside the checkout and do not add test infrastructure.

Comment thread src/modules/ttmlLyrics.test.ts Outdated
@@ -0,0 +1,41 @@
import assert from 'node:assert/strict'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this newly added test file as well. The repository has no approved test layout, and this file must not remain in the PR.

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Removed both added lyrics test files. The lyrics implementation is unchanged.

Fork CI on 13c12ad: type-check and build passed, generated output matched, and Node.js 22/24 each passed 34 tests (3 skipped), with 32 passing in Bun and no failures. Regression harnesses ran in a temporary directory outside the checkout; no test infrastructure was added to the PR. Validation log. These results do not establish independent upstream validation or live Discord playback.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rechecked the exact current diff at 13c12ad: the requested source and generated test files have been removed, with no replacement test directory or runner. The TTML parser is explicitly bounded and rejects DTD/entity declarations; playback only emits timed events when provider line timing is complete, and stale lyric requests are revision-guarded. I have not independently run type-check/build or live Unison/Discord synchronization in this environment, so this is a static review update rather than an approval.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I found one timing case the parser currently loses. When a TTML <div> or <body> carries a begin offset and its child <p> has no absolute begin, visit() recurses with only the lyric context; it never passes the parent time offset into collectLine(). For example, a paragraph at 00:00:05.000 inside a div beginning at 00:00:10.000 is emitted at 5 seconds instead of 15. Could you propagate the active parent begin/end through the traversal and add this case to your local regression harness? The current test files are correctly absent from the PR; please keep any harness outside the repository.

Comment thread src/modules/ttmlLyrics.ts Resolved
1Lucas1apk

This comment was marked as outdated.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rechecked commit e839473. The inherited timing is now propagated in src/modules/ttmlLyrics.ts:132-162, and the traversal passes the resolved timing context to child elements in src/modules/ttmlLyrics.ts:273-281. A <p begin="5s"> inside a <div begin="10s"> now resolves to 15 seconds, while the parent container's end bounds the child interval. The generated implementation in dist/src/modules/ttmlLyrics.js matches the TypeScript source, and the previously requested test files are no longer part of the PR diff.

The fork workflow for the exact submitted commit e839473 completed successfully, including type-checking, build, generated-output verification, and the external harness on Node.js 22, Node.js 24, and Bun.

Live Unison provider responses and synchronized playback in Discord have not been independently verified. This addresses the timing issue I reported, but it is not an approval of the PR.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The parent-relative timing regression is fixed, but I found a separate compatibility issue in the parser that prevents approval.

The official Unison repository fixture amazing-grace.ttml uses bare-decimal time values such as 12.000, 15.600 and 12.600, with itunes:timing="Word". parseTtmlTime() currently accepts offsets only when they have an ms, s, m or h suffix, or when they contain a clock colon. As a result, 12.000 is rejected. I reproduced this against the PR parser on Node 22: the fixture shape produces zero lyric lines and synced: false, so UnisonLyrics.getLyrics() returns loadType: 'empty'.

The nested-relative case from my previous review still passes. This is a separate regression against a TTML form already present in Unison's own repository. Please support bare-decimal seconds and add a regression case based on that fixture before requesting another review.

Comment thread src/modules/ttmlLyrics.ts
Number(offset[1]) * (factors[offset[2]?.toLowerCase() ?? ''] ?? NaN)
return Number.isSafeInteger(Math.round(ms)) ? Math.round(ms) : undefined
}
if (!/^\d+:\d{2}(?::\d{2})?(?:\.\d+)?$/.test(raw)) return undefined

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This rejects bare-decimal seconds. Unison's own amazing-grace.ttml fixture uses values such as begin="12.000", end="15.600" and span begin="12.600" with root itunes:timing="Word" (fixture). The current parser returns undefined for parseTtmlTime('12.000'); I reproduced parseTtmlLyrics() returning no lines for this fixture shape on Node 22. Please parse bare-decimal seconds as milliseconds too. The existing nested-relative regression is separate and now passes.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I found another TTML compatibility case after the inherited-offset fix. The official Unison amazing-grace.ttml fixture uses bare decimal timestamps (12.000, 15.600, 12.600) with itunes:timing="Word". parseTtmlTime() rejects these because the offset expression requires an ms, s, m or h suffix, and the clock expression requires a colon. I reproduced the fixture shape against this commit: the timestamps are all discarded and the parser returns no lyric lines. Could you support this timestamp form and keep the same interpretation consistent for begin, end and span? The nested parent-relative timing fix is separate and still looks correct.

Comment thread src/modules/ttmlLyrics.ts
Number(offset[1]) * (factors[offset[2]?.toLowerCase() ?? ''] ?? NaN)
return Number.isSafeInteger(Math.round(ms)) ? Math.round(ms) : undefined
}
if (!/^\d+:\d{2}(?::\d{2})?(?:\.\d+)?$/.test(raw)) return undefined

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This rejects Unison's existing bare-decimal TTML timestamps (12.000, 15.600, 12.600). I checked the official amazing-grace.ttml fixture: with itunes:timing="Word", these values are used throughout the <div>, <p> and <span> elements. Since parseTtmlTime() returns undefined, the parser drops the timed lines and the provider result becomes empty. Please parse this form as seconds and apply it consistently to begin/end/duration.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I checked the nested timing fix and agree that regression is addressed. I found a separate compatibility case in the current parser that still makes a valid Unison response empty.

Comment thread src/modules/ttmlLyrics.ts Outdated
export function parseTtmlTime(value?: string): number | undefined {
if (!value) return undefined
const raw = value.trim()
const offset = raw.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)$/i)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unison's own amazing-grace.ttml fixture uses bare-decimal timestamps such as 12.000, 15.600 and 12.600 with itunes:timing="Word". This offset regex only accepts a unit suffix, so parseTtmlTime('12.000') returns undefined; the parser then drops the timed elements and getLyrics() can return loadType: 'empty'. I reproduced this fixture shape against this commit on Node 22. Could you accept bare decimal seconds here and apply the same interpretation to begin, end and dur? The parent-relative case is separate and now passes.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The nested timing fix is good; it handles the parent-relative case without changing the explicitly absolute Word/Line path. I found one separate format that still causes valid Unison lyrics to be discarded.

Comment thread src/modules/ttmlLyrics.ts Outdated
export function parseTtmlTime(value?: string): number | undefined {
if (!value) return undefined
const raw = value.trim()
const offset = raw.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)$/i)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unison's amazing-grace.ttml uses bare decimal seconds such as begin="12.000", end="15.600" and span begin="12.600" under itunes:timing="Word". This regex only accepts a unit suffix, so these values parse as undefined; the timed nodes are then skipped and the provider can return empty lyrics. Please accept bare decimal seconds here and apply that interpretation consistently to begin, end and dur. The existing nested-relative fix is separate and should stay intact.

@1Lucas1apk 1Lucas1apk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rechecked the latest commit and the parent-relative timing fix is good. There is still a separate valid Unison timestamp format that this parser drops: its amazing-grace.ttml fixture uses bare decimal seconds such as 12.000, 15.600 and 12.600 with itunes:timing="Word". parseTtmlTime() currently accepts decimal offsets only when they have a unit suffix, then rejects these values in the clock-format branch. That makes the timed elements disappear and can leave the provider with empty lyrics. Could you accept bare decimal seconds as milliseconds-to-seconds input (convert to ms), and add the same case to your external regression harness? I reproduced the rejection against the current parser expression.

Comment thread src/modules/ttmlLyrics.ts Outdated
export function parseTtmlTime(value?: string): number | undefined {
if (!value) return undefined
const raw = value.trim()
const offset = raw.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)$/i)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unison's TTML uses bare decimal seconds here (12.000, 15.600, 12.600) under itunes:timing="Word". This regex requires an ms/s/m/h suffix, and the later clock regex requires a colon, so these valid values return undefined. The parser then skips the timed nodes and may return empty lyrics. Please handle bare decimals as seconds as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for identifying the Unison timestamp format. Fixed in 0c0c8ff: bare seconds now convert to milliseconds in the shared parser for begin/end/dur, without changing the nested-relative fix or explicit iTunes absolute timing. I audited all 15 official TTML fixtures pinned to Unison 5521c80, with their blob hashes verified in a temporary directory outside the checkout. The complete Amazing Grace fixture went from 4 to 16 synchronized lines and now returns 98 timed words; both 90210 revisions and all 12 intentionally malformed fixtures produced identical output to the previous revision. The latter comparison is not a claim of full XML conformance. The regression also checks 12.600 -> 12,600 ms, duration bounds, and source/compiled parity. Exact-HEAD fork CI completed successfully: type-check, build, generated output, Node 22/24 (34 passed, 3 skipped each), Bun (32 passed), focused assertions, official fixture audit and clean checkout. No test files or workflow changes were added to this PR. Live Unison responses and Discord playback synchronization remain unverified.

@TheFrogEcliptia TheFrogEcliptia left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed the current diff at 0c0c8ff. The TTML parser now handles the parent-relative timing case and Unison's bare-decimal second timestamps while preserving the explicitly media-absolute iTunes Word/Line timing path. The lyrics timing metadata and playback synchronization changes are consistent with those semantics, and I found no remaining blocking issue in the reviewed diff. The contributor reports exact-HEAD fork CI, fixture coverage and a clean build/type-check; live provider responses and end-to-end Discord synchronization were not independently verified here. Approved.

@1Lucas1apk
1Lucas1apk merged commit 72482b7 into PerformanC:dev Nov 29, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants