Use AutoEngine to automatically select and manage between SparkTTS, OrpheusTTS, or MegaTTS based on your model directory structure. It provides a unified interface for speech synthesis, voice cloning, and multi-speaker dialogue across different model architectures.
Engine Auto-Detection Logic
AutoEngine identifies the engine by checking for specific subdirectories in your model_path:
- Spark: Requires
LLM, BiCodec, and wav2vec2-large-xlsr-53 directories. - Mega: Requires
aligner_lm, diffusion_transformer, duration_lm, g2p, and wavvae directories. - Orpheus: Detected if a
snac directory exists or if snac_path is explicitly provided.
If none of these patterns match, a RuntimeError: No engine found is raised.
import asyncio
from flashtts import AutoEngine
# AutoEngine automatically detects if this is Spark, Orpheus, or Mega
engine = AutoEngine(
model_path="checkpoints/YourModelDir",
snac_path=None, # Required for Orpheus if `snac` subdirectory is not present
lang="mandarin", # Only used by Orpheus
llm_device="cuda",
tokenizer_device="cuda",
detokenizer_device="cuda",
backend="vllm",
torch_dtype="float32",
batch_size=1,
llm_batch_size=256,
wait_timeout=0.01,
seed=42
)
async def main():
# Basic synthesis example
wav = await engine.speak_async(
text="Hello, world!",
name="female",
pitch="moderate",
speed="moderate",
temperature=0.9,
top_k=50,
top_p=0.95
)
engine.write_audio(wav, "output.wav")
if __name__ == '__main__':
asyncio.run(main())