feat(lyric): 丰富 AMLL 设置项,删除 QM 意外的逐字音译#726
Conversation
Summary of ChangesHello @MoYingJi, 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! 此拉取请求旨在增强歌词显示的用户自定义能力,特别是针对 Apple Music Like Lyrics (AMLL) 模式。通过引入新的设置选项,用户现在可以更灵活地控制歌词翻译、整体罗马音以及逐字罗马音的可见性。同时,内部歌词处理逻辑也得到了优化,使得罗马音的解析和应用更加模块化和独立。 Highlights
Using Gemini Code AssistThe 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
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 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
|
| isDuet: false, | ||
| }; | ||
| }); | ||
| result = this.alignLyrics(result, romaLines, "romanLyric"); |
There was a problem hiding this comment.
alignLyrics 函数由于存在嵌套循环,其时间复杂度为 O(N*M),其中 N 和 M 分别是主歌词和罗马音歌词的行数。对于歌词行数较多的歌曲,这可能会导致性能瓶颈。
建议优化 alignLyrics 函数,采用更高效的算法,例如在歌词按时间排序的前提下使用双指针法。这将能把时间复杂度降低到 O(N+M),从而显著提高长歌词的处理性能。
一个使用双指针法的高效实现示例(假设两个歌词数组都按 startTime 排序):
private alignLyrics(
lyrics: LyricLine[],
otherLyrics: LyricLine[],
key: "translatedLyric" | "romanLyric",
): LyricLine[] {
if (!lyrics.length || !otherLyrics.length) {
return lyrics;
}
let otherIdx = 0;
for (const line of lyrics) {
// 移动 otherIdx 寻找可能的匹配项
while (
otherIdx < otherLyrics.length - 1 &&
otherLyrics[otherIdx].startTime < line.startTime - 300
) {
otherIdx++;
}
// 检查 otherLyrics 中当前及附近的歌词行以寻找匹配
for (let i = otherIdx; i < otherLyrics.length; i++) {
const otherLine = otherLyrics[i];
const timeDiff = Math.abs(line.startTime - otherLine.startTime);
if (timeDiff < 300) {
line[key] = otherLine.words.map((word) => word.word).join("");
// 原始实现会继续查找,并让最后一个匹配项生效。
// 如果只需要第一个匹配项,可以在此处 `break`。
}
// 如果 otherLine 的时间已经远超当前行的时间,则停止搜索
if (otherLine.startTime > line.startTime + 300) {
break;
}
}
}
return lyrics;
}
cloneDeep后的歌词的翻译和音译来实现了 AMLL 的:不显示翻译、不显示音译、不显示逐字音译index放入错误的逐字音译(QM 歌词的逐字音译无论从index还是startTime/endTime都是对不上的,只能合并为逐行)renderScalelowFreqVolume的逻辑,之前的逻辑会导致暂停后lowFreqVolume突变为1,现在暂停则会保持