Spaces:
Running
Running
Michael Hu
fix: keep API parameter names, reject unknown voices, and stop cloned Chatterbox voices reaching other users
4d9637e Download tests/ui_test.py from DroolingPanda/tts_gallery: direct link, hf CLI and curl.
- Browser
- Download file 2.9 kB
-
https://huggingface.co/spaces/DroolingPanda/tts_gallery/resolve/main/tests/ui_test.py
- Command line
-
hf download hf://spaces/DroolingPanda/tts_gallery/tests/ui_test.py
-
curl -L -o ui_test.py https://huggingface.co/spaces/DroolingPanda/tts_gallery/resolve/main/tests/ui_test.py
2.9 kB
| """Check the UI wiring with fake models, no downloads: python -m tests.ui_test""" | |
| import gradio as gr | |
| from src.ui import create_interface | |
| class FakeTTS: | |
| def __init__(self): | |
| self.calls = [] | |
| def get_supported_languages(self): | |
| return ["English", "Chinese"] | |
| def get_available_voices(self, language=None): | |
| return ["v1", "v2"] | |
| def get_default_voice(self): | |
| return "v2" | |
| def generate_speech(self, text, **kwargs): | |
| self.calls.append((text, kwargs)) | |
| return "out.wav" | |
| class FakeSTT: | |
| languages = {"English": "en"} | |
| def __init__(self): | |
| self.calls = [] | |
| def transcribe(self, audio_path, language=None): | |
| self.calls.append((audio_path, language)) | |
| return "heard" | |
| TTS_NAMES = [ | |
| "ResembleAI/chatterbox", | |
| "KittenML/KittenTTS", | |
| "KittenML/kitten-tts-2", | |
| "piper-tts", | |
| "hexgrad/kokoro", | |
| ] | |
| STT_NAMES = ["SYSTRAN/faster-whisper", "Cactus-Compute/whistle"] | |
| def main(): | |
| tts = {name: FakeTTS() for name in TTS_NAMES} | |
| stt = {name: FakeSTT() for name in STT_NAMES} | |
| demo = create_interface(tts, stt) | |
| fns = {f.api_name: f.fn for f in demo.fns.values()} | |
| api = demo.get_api_info()["named_endpoints"] | |
| params = {name: [(p["parameter_name"], p["parameter_has_default"]) for p in ep["parameters"]] for name, ep in api.items()} | |
| assert params["/tts_chatterbox"] == [("text", False), ("language", True), ("audio_prompt", True)], params | |
| assert params["/stt_whistle"] == [("audio", False), ("lang", True)], params | |
| assert not any(name.startswith("/update_voices") for name in api), sorted(api) | |
| expected = { | |
| "tts_chatterbox", | |
| "tts_kittentts", | |
| "tts_kittentts2", | |
| "tts_piper", | |
| "tts_kokoro", | |
| "stt_whisper", | |
| "stt_whistle", | |
| } | |
| assert expected <= set(fns), sorted(fns) | |
| fns["tts_chatterbox"]("hi", "Chinese", "ref.wav") | |
| assert tts["ResembleAI/chatterbox"].calls[-1] == ( | |
| "hi", | |
| {"language": "Chinese", "audio_prompt": "ref.wav"}, | |
| ) | |
| fns["tts_kokoro"]("hi", "English", "v2") | |
| assert tts["hexgrad/kokoro"].calls[-1] == ( | |
| "hi", | |
| {"language": "English", "voice": "v2"}, | |
| ) | |
| fns["tts_kittentts2"]("hi", "v1", "stable", "ref.wav", "") | |
| assert tts["KittenML/kitten-tts-2"].calls[-1][1]["reference_text"] == "heard" | |
| assert stt["SYSTRAN/faster-whisper"].calls[-1] == ("ref.wav", None) | |
| assert fns["stt_whistle"]("clip.wav", "auto") == "heard" | |
| fns["stt_whistle"]("clip.wav", "en") | |
| assert stt["Cactus-Compute/whistle"].calls == [ | |
| ("clip.wav", None), | |
| ("clip.wav", "en"), | |
| ] | |
| try: | |
| fns["tts_kittentts"](" ", "v1") | |
| raise AssertionError("empty text must be rejected") | |
| except gr.Error as e: | |
| assert "Enter some text" in str(e), e | |
| print("ui test passed") | |
| if __name__ == "__main__": | |
| main() | |