Merge #2444 from rudycelekli

This commit is contained in:
Bingxi Zhao (Frank)
2026-11-06 01:56:26 +08:00
2 changed files with 15 additions and 1 deletions

View File

@@ -90,7 +90,11 @@ def _configured_voice(language: str) -> str | None:
voice = getattr(config, "voice", "") or ""
if getattr(config, "provider_name", "") != "edge" or not voice:
return None
return voice if voice.lower().startswith(_lang(language)) else None
# Compare against the lesson's own language, not ``_lang``: that collapses
# every non-Chinese language to "en", so a French lesson would reject a
# configured ``fr-FR`` voice and accept an ``en-US`` one instead.
base = (language or "").strip().lower().replace("_", "-").split("-", 1)[0]
return voice if base and voice.lower().startswith(f"{base}-") else None
def _settings_provider() -> str | None:

View File

@@ -51,6 +51,16 @@ def test_settings_edge_voice_is_used_for_its_language(monkeypatch) -> None:
assert narration._configured_voice("zh") is None
def test_settings_edge_voice_matches_languages_beyond_zh_and_en(monkeypatch) -> None:
_tts(monkeypatch, provider_name="edge", voice="fr-FR-DeniseNeural")
assert narration._configured_voice("fr") == "fr-FR-DeniseNeural"
assert narration._configured_voice("en") is None
_tts(monkeypatch, provider_name="edge", voice="en-US-AndrewMultilingualNeural")
assert narration._configured_voice("fr") is None
assert narration._configured_voice("pt") is None
def test_non_edge_tts_settings_keep_the_default_voice(monkeypatch) -> None:
_tts(monkeypatch, provider_name="openai", voice="alloy")
assert narration._configured_voice("en") is None