Spaces:
Build error
Build error
| import sys | |
| from types import SimpleNamespace | |
| import pytest | |
| import signspeak.tts as tts_module | |
| class FakeTTS: | |
| def generate_custom_voice(self, text, language, speaker, instruct): | |
| assert text == "Hello." | |
| assert language == "English" | |
| assert speaker == "Ryan" | |
| assert instruct == "Speak clearly." | |
| return [[0.0, 0.1, 0.0]], 24000 | |
| def test_generate_tts_uses_model_and_writes_file(monkeypatch, tmp_path): | |
| writes = [] | |
| def fake_write(path, data, sample_rate): | |
| writes.append((path, data, sample_rate)) | |
| monkeypatch.setattr(tts_module, "get_tts_model", lambda: FakeTTS()) | |
| monkeypatch.setattr(tts_module.tempfile, "gettempdir", lambda: str(tmp_path)) | |
| monkeypatch.setitem(sys.modules, "soundfile", SimpleNamespace(write=fake_write)) | |
| output_path = tts_module.generate_tts("Hello.", "English", "Ryan", "Speak clearly.") | |
| assert output_path.startswith(str(tmp_path)) | |
| assert writes == [(output_path, [0.0, 0.1, 0.0], 24000)] | |
| def test_generate_tts_rejects_empty_text(): | |
| with pytest.raises(ValueError): | |
| tts_module.generate_tts("", "English", "Ryan", "Speak clearly.") | |