| from pathlib import Path | |
| import pytest | |
| from backend.magpie_adapter import MagpieAdapter | |
| from backend.types import VoiceConfig | |
| def test_magpie_adapter_raises_when_runtime_is_unavailable(tmp_path: Path) -> None: | |
| adapter = MagpieAdapter() | |
| adapter._load_error = ModuleNotFoundError("No module named 'nemo'") | |
| with pytest.raises(ValueError, match="Magpie TTS runtime is unavailable"): | |
| adapter.synthesize( | |
| text="Hello from Magpie.", | |
| output_path=tmp_path / "magpie.wav", | |
| voice_config=VoiceConfig(model="magpie", speaker="Sofia", language="en"), | |
| diffusion_steps=32, | |
| speed=1.0, | |
| ) | |
| def test_magpie_adapter_uses_official_speaker_mapping() -> None: | |
| adapter = MagpieAdapter() | |
| assert adapter.speaker_index_for("John") == 0 | |
| assert adapter.speaker_index_for("Sofia") == 1 | |
| assert adapter.speaker_index_for("Aria") == 2 | |
| assert adapter.speaker_index_for("Jason") == 3 | |
| assert adapter.speaker_index_for("Leo") == 4 | |