Skip to content

Commit

Permalink
lrc和ass支持忽略连音符;lrc拉丁语言自动空格分隔 (#674)
Browse files Browse the repository at this point in the history
* .lrc and .ass plugin: support ignoring slur '-' lyrics

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
oxygen-dioxide and pre-commit-ci[bot] authored Jan 20, 2025
1 parent ca630b8 commit 780c43d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions libresvip/plugins/ass/ass_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ def generate_project(self, project: Project) -> SSAFile:
buffer = []
return lyric_lines

def lyric_included(self, lyric: str) -> bool:
if self.options.ignore_slur_notes:
return lyric != "-"
else:
return True

def commit_current_lyric_line(self, lyric_lines: list[SSAEvent], buffer: list[Note]) -> None:
start_time = int(self.synchronizer.get_actual_secs_from_ticks(buffer[0].start_pos) * 1000)
end_time = int(self.synchronizer.get_actual_secs_from_ticks(buffer[-1].end_pos) * 1000)
lyrics = "".join(
SYMBOL_PATTERN.sub("", note.lyric)
+ (" " if LATIN_ALPHABET.search(note.lyric) is not None else "")
for note in buffer
if self.lyric_included(note.lyric)
)
lyric_lines.append(
SSAEvent(
Expand Down
7 changes: 7 additions & 0 deletions libresvip/plugins/ass/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ class OutputOptions(SelectSingleTrackMixin, BaseModel):
description=_("In milliseconds, positive means ahead, negative means opposite."),
)
split_by: SplitOption = Field(title=_("New line by"), default=SplitOption.BOTH)
ignore_slur_notes: bool = Field(
title=_("Ignore slur notes"),
description=_(
"Ignore '-' lyrics that are used to indicate slur notes in singing synthesizers."
),
default=True,
)
encoding: str = Field(title=_("Text encoding"), default="utf-8")
13 changes: 11 additions & 2 deletions libresvip/plugins/lrc/lrc_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from libresvip.core.time_sync import TimeSynchronizer
from libresvip.model.base import Project, SingingTrack
from libresvip.utils.text import SYMBOL_PATTERN
from libresvip.utils.text import LATIN_ALPHABET, SYMBOL_PATTERN

from .model import (
AlbumInfoTag,
Expand Down Expand Up @@ -81,13 +81,22 @@ def generate_project(self, project: Project) -> LrcFile:
info_tags=info_tags,
)

def lyric_included(self, lyric: str) -> bool:
if self.options.ignore_slur_notes:
return lyric != "-"
else:
return True

def commit_current_lyric_line(
self, lyric_lines: list[LyricLine], buffer: list[tuple[int, str]]
) -> None:
start_time = self.get_time_from_ticks(buffer[0][0])
lyrics = ""
for _, lyric in buffer:
lyrics += SYMBOL_PATTERN.sub("", lyric)
if self.lyric_included(lyric):
lyrics += SYMBOL_PATTERN.sub("", lyric) + (
" " if LATIN_ALPHABET.search(lyric) is not None else ""
)
lyric_lines.append(
LyricLine(
time_tags=[
Expand Down
7 changes: 7 additions & 0 deletions libresvip/plugins/lrc/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class OutputOptions(BaseModel):
title=_("Offset policy"), default=OffsetPolicyOption.TIMELINE
)
split_by: SplitOption = Field(title=_("New line by"), default=SplitOption.BOTH)
ignore_slur_notes: bool = Field(
title=_("Ignore slur notes"),
description=_(
"Ignore '-' lyrics that are used to indicate slur notes in singing synthesizers."
),
default=True,
)
timeline: bool = Field(
title=_("Write timeline"),
description=_("If you need lyrics without timeline, turn off this option."),
Expand Down

0 comments on commit 780c43d

Please sign in to comment.