#!/bin/bash

[ -f speech.env ] && . speech.env

# Default to 1 worker for GPU models (Qwen3-TTS)
WORKERS=${WORKERS:-1}

echo "First startup may download ~3GB of Qwen3-TTS model + ~1.5GB of F5-TTS model. Please wait."

# Pre-download Qwen3-TTS model (default engine)
python -c "from qwen_tts import Qwen3TTSModel; Qwen3TTSModel.from_pretrained('Qwen/Qwen3-TTS-12Hz-1.7B-Base')" 2>/dev/null || echo "Qwen3-TTS will download on first request"

# Pre-download F5-TTS model (default engine, additive)
python -c "from f5_tts.api import F5TTS; F5TTS()" 2>/dev/null || echo "F5-TTS will download on first request"

# Optional: download legacy engines if enabled
# bash download_voices_tts-1.sh
# bash download_voices_tts-1-hd.sh $PRELOAD_MODEL

python speech.py --workers $WORKERS ${PRELOAD_MODEL:+--preload $PRELOAD_MODEL} $EXTRA_ARGS $@
