Skip to content

Commit

Permalink
srt: support ignoring slur notes (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxygen-dioxide authored Jan 21, 2025
1 parent b58b4e9 commit 0e76494
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libresvip/plugins/srt/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")
7 changes: 7 additions & 0 deletions libresvip/plugins/srt/srt_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)
).strip()
lyric_lines.append(
SSAEvent(
Expand Down

0 comments on commit 0e76494

Please sign in to comment.