Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

refactor(lyricParser): 修正并移动 alignLocalLyrics - #995

Merged
imsyy merged 2 commits into
SPlayer-Dev:devfrom
MoYingJi:pr/ral
Mar 13, 2026
Merged

imsyy merged 2 commits into
SPlayer-Dev:devfrom
MoYingJi:pr/ral

Conversation

@MoYingJi

Copy link
Copy Markdown
Collaborator

将 LyricManager 的 alignLocalLyrics 移动到了 lyricParser 并重命名为 alignLyricLines

修了一下,使之考虑了逐字歌词,设置结束时间时也考虑 words;增加了两个参数 endTime 和 maxTimeDiff 用于指定是否考虑结束时间和允许的时间差

同时修复了 alignLyricLines 注释中的单位错误,更改 maxTimeDiff 默认值为 0(0.6 ms 没必要比了,直接 0 吧)

Copilot AI review requested due to automatic review settings March 13, 2026 16:22
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过将歌词对齐逻辑从 LyricManager 类中解耦并移动到一个独立的工具函数中,来提高代码的模块化和可维护性。这一重构不仅使得歌词对齐功能更加通用,还增强了其处理复杂歌词格式(如逐字歌词)的能力,并提供了更精细的控制选项,从而提升了歌词显示的准确性和用户体验。

Highlights

  • 代码重构与移动: 将 LyricManager 类中的私有方法 alignLocalLyrics 移动到 lyricParser 工具模块,并重命名为 alignLyricLines,使其成为一个可导出的通用函数。
  • 歌词对齐逻辑增强: 新的 alignLyricLines 函数现在能够更好地处理逐字歌词(words 属性),并在设置结束时间时考虑 words 数组中最后一个字的结束时间。
  • 新增配置参数: 为 alignLyricLines 增加了 endTime 和 maxTimeDiff 两个可选参数,允许更灵活地控制结束时间的处理方式和歌词行匹配的时间容差。
  • 默认值与注释修正: 修复了 alignLyricLines 函数注释中的单位错误,并将 maxTimeDiff 的默认值从 0.6 毫秒更改为 0,以实现更严格的时间匹配。
Changelog
  • src/core/player/LyricManager.ts
    • 移除了私有方法 alignLocalLyrics。
    • 更新了所有调用 alignLocalLyrics 的地方,改为导入并使用 lyricParser 中的 alignLyricLines 函数。
    • 新增了对 alignLyricLines 的导入。
  • src/utils/lyric/lyricParser.ts
    • 新增了导出的 alignLyricLines 函数,包含了原 alignLocalLyrics 的逻辑,并进行了功能增强。
    • 在 alignLyricLines 中增加了对逐字歌词 words 的处理,以更准确地计算歌词行的结束时间。
    • 为 alignLyricLines 引入了 endTime 和 maxTimeDiff 参数,以支持更灵活的对齐策略。
    • 修正了 alignLyricLines 函数注释中关于时间单位的描述错误,并将 maxTimeDiff 的默认值设为 0。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

这次重构做得很好,将 alignLocalLyrics 函数从 LyricManager 移动到 lyricParser 并重命名为 alignLyricLines,显著提高了代码的模块化和可维护性。新函数增加了 endTime 和 maxTimeDiff 参数,使其更加灵活和强大,同时修复了之前版本中对逐字歌词处理和时间戳比较的缺陷。

不过,在审查新实现时,我发现了一些小问题,可能会导致意外的行为或运行时错误。具体细节请看我的评论。

Comment thread src/utils/lyric/lyricParser.ts
Comment thread src/utils/lyric/lyricParser.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

本 PR 将 LyricManager 内的本地歌词对齐逻辑抽离到 lyricParser,并重命名为 alignLyricLines,用于按时间戳将同一时间的多行歌词合并为“主句 + 翻译 + 音译”。

Changes:

  • 新增 alignLyricLines:支持逐字歌词的时间字段读取,并新增 endTime / maxTimeDiff 参数以控制结束时间与时间差匹配策略
  • 移除 LyricManager#alignLocalLyrics,并在本地歌词解析/覆盖等路径改用 alignLyricLines
  • 修正(意图)注释单位与默认阈值策略(默认严格匹配)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/utils/lyric/lyricParser.ts 新增 alignLyricLines,承载本地多行歌词的翻译/音译合并逻辑,并引入结束时间与时间差策略参数
src/core/player/LyricManager.ts 删除旧的 alignLocalLyrics,在本地歌词与覆盖歌词处理链路中切换为调用 alignLyricLines

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/utils/lyric/lyricParser.ts
Comment thread src/utils/lyric/lyricParser.ts
Comment thread src/utils/lyric/lyricParser.ts
Comment on lines +364 to +369
if (baseLine.words?.length) {
const lastWord = baseLine.words[baseLine.words.length - 1];
const lastWordEndTime = lastWord.endTime;
if (lastWordEndTime === oldEndTime) {
lastWord.endTime = addEndTime;
}
将 LyricManager 的 alignLocalLyrics 移动到了 lyricParser 并重命名为 alignLyricLines

修了一下,使之考虑了逐字歌词,设置结束时间时也考虑 `words`;增加了两个参数 `endTime` 和 `maxTimeDiff` 用于指定是否考虑结束时间和允许的时间差
@imsyy
imsyy merged commit 5c64302 into SPlayer-Dev:dev Mar 13, 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