Merge 17c7cf5f9bdee0ef8d2bb639dfb9bd42eade5a93 into e7cd61ec3dcc9a34089f50ed169e3103a16ad675

This commit is contained in:
Igor Baranov 2026-10-07 23:57:20 +03:00 committed by GitHub
commit 1c6fa0216f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 0 deletions

View 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

View 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)