mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2026-11-30 04:53:34 +08:00
Merge 17c7cf5f9bdee0ef8d2bb639dfb9bd42eade5a93 into e7cd61ec3dcc9a34089f50ed169e3103a16ad675
This commit is contained in:
commit
1c6fa0216f
45
GPT_SoVITS/text/russian.py
Normal file
45
GPT_SoVITS/text/russian.py
Normal file
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Russian phoneme helpers.
|
||||
|
||||
This module contains the checkpoint-facing normalization used to convert
|
||||
Epitran-style XSAMPA symbols into the compact Latin inventory expected by
|
||||
Russian GPT-SoVITS checkpoints.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
_XSAMPA_BASE_MAP = {
|
||||
"1": "I",
|
||||
"@": "A",
|
||||
"6": "A",
|
||||
"s`": "S",
|
||||
"S`": "S",
|
||||
}
|
||||
_ALLOWED_BASES = frozenset("ABDEFGIJKLMNOPRSTUVXZ")
|
||||
|
||||
|
||||
def normalize_xsampa_symbol(symbol: str) -> str:
|
||||
"""Normalize one Russian XSAMPA symbol to the checkpoint base inventory.
|
||||
|
||||
Epitran emits multi-character and modified symbols for Russian, including
|
||||
palatalized consonants (for example ``d'``), long vowels, and ``s``` for
|
||||
Russian ``ш`` (IPA ``ʂ``). Russian checkpoints use a collapsed uppercase
|
||||
base inventory, so supported modifiers are removed after resolving known
|
||||
multi-character symbols.
|
||||
|
||||
Raises:
|
||||
ValueError: if the normalized symbol is outside the supported Russian
|
||||
checkpoint inventory.
|
||||
"""
|
||||
|
||||
if not isinstance(symbol, str) or not symbol:
|
||||
raise ValueError("Russian XSAMPA symbol must be a non-empty string")
|
||||
|
||||
normalized = _XSAMPA_BASE_MAP.get(symbol, symbol)
|
||||
normalized = normalized.replace("'", "").replace(":", "").replace("\\", "")
|
||||
normalized = _XSAMPA_BASE_MAP.get(normalized, normalized).upper()
|
||||
|
||||
if normalized not in _ALLOWED_BASES:
|
||||
raise ValueError(f"Unsupported Russian XSAMPA symbol: {symbol!r}")
|
||||
return normalized
|
||||
28
tests/test_russian_phonemes.py
Normal file
28
tests/test_russian_phonemes.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from GPT_SoVITS.text.russian import normalize_xsampa_symbol
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("symbol", "expected"),
|
||||
[
|
||||
("d'", "D"),
|
||||
("n'", "N"),
|
||||
("r'", "R"),
|
||||
("l'", "L"),
|
||||
("a:", "A"),
|
||||
("1", "I"),
|
||||
("@", "A"),
|
||||
("6", "A"),
|
||||
("s`", "S"),
|
||||
("S`", "S"),
|
||||
],
|
||||
)
|
||||
def test_normalize_russian_xsampa_symbol(symbol, expected):
|
||||
assert normalize_xsampa_symbol(symbol) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("symbol", ["", "?", "t_s", None])
|
||||
def test_normalize_russian_xsampa_symbol_rejects_unsupported_input(symbol):
|
||||
with pytest.raises(ValueError, match="Russian XSAMPA|Unsupported Russian"):
|
||||
normalize_xsampa_symbol(symbol)
|
||||
Loading…
x
Reference in New Issue
Block a user