From 0e76494ddbc201c93f3521faa76e21dfd3e2ba11 Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Tue, 21 Jan 2025 19:04:54 +0800 Subject: [PATCH] srt: support ignoring slur notes (#677) --- libresvip/plugins/srt/options.py | 7 +++++++ libresvip/plugins/srt/srt_generator.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/libresvip/plugins/srt/options.py b/libresvip/plugins/srt/options.py index f33bc1df1..d80c4521b 100644 --- a/libresvip/plugins/srt/options.py +++ b/libresvip/plugins/srt/options.py @@ -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") diff --git a/libresvip/plugins/srt/srt_generator.py b/libresvip/plugins/srt/srt_generator.py index 28faf77b9..b5c8656cb 100644 --- a/libresvip/plugins/srt/srt_generator.py +++ b/libresvip/plugins/srt/srt_generator.py @@ -45,6 +45,12 @@ 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) @@ -52,6 +58,7 @@ def commit_current_lyric_line(self, lyric_lines: list[SSAEvent], buffer: list[No 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(