diff --git a/speech.py b/speech.py index c576abd..315d7e0 100755 --- a/speech.py +++ b/speech.py @@ -82,10 +82,18 @@ ENGINE_SHORT_TO_MODEL = { } ALL_MODEL_IDS = set(ENGINE_SHORT_TO_MODEL.values()) +# Lean default — F5 alone fits comfortably on a GPU shared with an LLM. +# Override with --engines (or SPEECH_ENABLED_ENGINES env var): +# --engines f5,piper -> {tts-1-f5, tts-1} +# --engines all -> no allowlist (every importable engine enabled) +DEFAULT_ENGINES = frozenset({'tts-1-f5'}) + def _parse_engines_env(): raw = os.environ.get('SPEECH_ENABLED_ENGINES', '').strip() if not raw: - return None + return set(DEFAULT_ENGINES) + if raw.lower() == 'all': + return None # explicit opt-in to every engine allowed = set() for e in (s.strip() for s in raw.split(',')): if not e: @@ -98,11 +106,11 @@ def _parse_engines_env(): raise ValueError( f"SPEECH_ENABLED_ENGINES: unknown engine '{e}' " f"(valid short names: {', '.join(sorted(ENGINE_SHORT_TO_MODEL))}, " - f"or full tts-1-* ids)" + f"full tts-1-* ids, or the keyword 'all')" ) return allowed -ENABLED_ENGINES = _parse_engines_env() # None = all enabled; set = allowlist +ENABLED_ENGINES = _parse_engines_env() # None = unrestricted; set = allowlist def is_engine_available(model_id): """Whether the TTS engine for a given model_id is loadable in this process. @@ -1539,9 +1547,8 @@ if __name__ == "__main__": help="Comma-separated allowlist of TTS engines to enable. " "Short names: f5, qwen, piper, xtts, silero, kokoro " "(or full model IDs like tts-1-f5). " - "Default: all engines enabled. " - "Example: --engines f5,piper keeps speech lean enough to " - "share GPU with an LLM server.") + "Pass --engines all to enable every importable engine. " + "Default: f5 only (lean, fits on a GPU shared with an LLM).") args = parser.parse_args() @@ -1549,7 +1556,9 @@ if __name__ == "__main__": logger.add(sink=sys.stderr, level=args.log_level) # Propagate --engines to uvicorn workers via env var (workers re-import - # this module + read SPEECH_ENABLED_ENGINES into ENABLED_ENGINES). + # this module + read SPEECH_ENABLED_ENGINES into ENABLED_ENGINES at + # module load). When --engines is omitted, the env var stays unset + # and _parse_engines_env() falls through to DEFAULT_ENGINES (f5 only). if args.engines: os.environ['SPEECH_ENABLED_ENGINES'] = args.engines try: @@ -1557,9 +1566,13 @@ if __name__ == "__main__": except ValueError as e: logger.error(str(e)) sys.exit(2) - logger.info(f"--engines: restricting to {sorted(ENABLED_ENGINES)}") + if ENABLED_ENGINES is None: + logger.info("--engines all: every importable engine enabled") + else: + logger.info(f"--engines: restricting to {sorted(ENABLED_ENGINES)}") else: - logger.info("All engines enabled (no --engines restriction)") + logger.info(f"Default engine allowlist: {sorted(ENABLED_ENGINES)} " + f"(pass --engines all or --engines f5,qwen,... to override)") if args.preload and not XTTS_AVAILABLE: logger.error("Cannot preload XTTS model - XTTS dependencies not available")