mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-07 05:47:56 +08:00
Merge #2444 from rudycelekli
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user