diff --git a/deeptutor/agents/video_lesson/narration.py b/deeptutor/agents/video_lesson/narration.py index c90d24086..dd1bff7a7 100644 --- a/deeptutor/agents/video_lesson/narration.py +++ b/deeptutor/agents/video_lesson/narration.py @@ -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: diff --git a/tests/agents/video_lesson/test_narration.py b/tests/agents/video_lesson/test_narration.py index 82551354c..cadc4c514 100644 --- a/tests/agents/video_lesson/test_narration.py +++ b/tests/agents/video_lesson/test_narration.py @@ -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