Skip to content

Commit

Permalink
update vocaloid phoneme parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Jan 22, 2024
1 parent ad4be06 commit 3f50966
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
3 changes: 1 addition & 2 deletions libresvip/plugins/svip/binsvip_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,12 @@ def generate_note(self, note: Note) -> XSNote:
value=svip_note_head_tags.get(note.head_tag, XSNoteHeadTagEnum.NoTag)
),
lyric=note.lyric or DEFAULT_CHINESE_LYRIC,
pronouncing=note.pronunciation or "",
)
xs_note.width_pos = (
round(self.synchronizer.get_actual_ticks_from_ticks(note.end_pos))
- xs_note.start_pos
)
if note.pronunciation:
xs_note.pronouncing = note.pronunciation
if note.edited_phones is not None:
xs_note.note_phone_info = self.generate_phones(note.edited_phones)
if note.vibrato is not None:
Expand Down
2 changes: 1 addition & 1 deletion libresvip/plugins/vpr/vpr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def parse_notes(self, notes: list[VocaloidNotes], pos: int, default_lyric: str)
length=note.duration,
key_number=note.number,
lyric=note.lyric or default_lyric,
pronunciation=note.phoneme,
pronunciation=None,
)
for note in notes
]
12 changes: 12 additions & 0 deletions libresvip/plugins/vsq/options.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from enum import Enum
from typing import Annotated

from pydantic import BaseModel, Field


class BreathOption(Enum):
IGNORE: Annotated[str, Field(title="Ignore all breath notes")] = "ignore"
KEEP: Annotated[str, Field(title="Keep as normal notes")] = "keep"


class InputOptions(BaseModel):
lyric_encoding: str = Field(
default="shift-jis",
title="Lyric text encoding",
description="Unless the lyrics are garbled, this option should not be changed.",
)
breath: BreathOption = Field(
default=BreathOption.IGNORE,
title="The way to handle breath notes",
)


class OutputOptions(BaseModel):
Expand Down
14 changes: 11 additions & 3 deletions libresvip/plugins/vsq/vsq_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configparser
import dataclasses
import math
import re
from typing import Optional

import mido_fix as mido
Expand All @@ -16,13 +17,15 @@
TimeSignature,
)

from .options import InputOptions
from .options import BreathOption, InputOptions
from .vocaloid_pitch import (
ControllerEvent,
VocaloidPartPitchData,
pitch_from_vocaloid_parts,
)

BREATH_PATTERN = re.compile("br[1-5]")


@dataclasses.dataclass
class VsqParser:
Expand Down Expand Up @@ -188,16 +191,21 @@ def parse_notes(self, vsq_track: configparser.ConfigParser, tick_prefix: int) ->
if vsq_note["type"] == "Anote":
if (length := vsq_note.getint("length")) and (key := vsq_note.getint("note#")):
lyric_handle = vsq_note.get("lyrichandle", fallback="")
lyric_value, xsampa_value = vsq_track.get(
lyric_value, phoneme_value = vsq_track.get(
lyric_handle, "L0", fallback=","
).split(",")[:2]
if (
self.options.breath == BreathOption.IGNORE
and BREATH_PATTERN.fullmatch(phoneme_value.strip('"')) is not None
):
continue
notes.append(
Note(
start_pos=tick,
length=length,
key_number=key,
lyric=lyric_value.strip('"'),
pronunciation=xsampa_value.strip('"'),
pronunciation=None,
)
)
return notes
2 changes: 1 addition & 1 deletion libresvip/plugins/vsqx/vsqx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def parse_notes(self, notes: list[VsqxNote], tick_offset: int) -> list[Note]:
start_pos=note.pos_tick + tick_offset,
length=note.dur_tick,
lyric=note.lyric or DEFAULT_ENGLISH_LYRIC,
pronunciation=note.phnms.value if note.phnms is not None else None,
pronunciation=None,
key_number=note.note_num,
)
for note in notes
Expand Down

0 comments on commit 3f50966

Please sign in to comment.