From 150b77110e43a7f412c280c72fc635093dfb8ca2 Mon Sep 17 00:00:00 2001 From: iibaranov-IG Date: Thu, 30 Jul 2026 02:15:28 -0700 Subject: [PATCH 1/2] feat(text): add Russian XSAMPA normalization helper --- GPT_SoVITS/text/russian.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 GPT_SoVITS/text/russian.py diff --git a/GPT_SoVITS/text/russian.py b/GPT_SoVITS/text/russian.py new file mode 100644 index 00000000..ce7731ed --- /dev/null +++ b/GPT_SoVITS/text/russian.py @@ -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 From 17c7cf5f9bdee0ef8d2bb639dfb9bd42eade5a93 Mon Sep 17 00:00:00 2001 From: iibaranov-IG Date: Thu, 30 Jul 2026 02:17:01 -0700 Subject: [PATCH 2/2] test(text): cover Russian XSAMPA normalization --- tests/test_russian_phonemes.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_russian_phonemes.py diff --git a/tests/test_russian_phonemes.py b/tests/test_russian_phonemes.py new file mode 100644 index 00000000..86a6287d --- /dev/null +++ b/tests/test_russian_phonemes.py @@ -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)