Files
Qwen3-tts/scripts/start_tts.sh

81 lines
3.1 KiB
Bash
Raw Normal View History

2026-06-18 17:27:42 +02:00
#!/bin/bash
set -e
2026-06-19 17:22:28 +02:00
cd "$(dirname "$0")/.."
2026-06-18 17:27:42 +02:00
HEALTH_URL="http://localhost:8091/health"
MAX_WAIT=180
2026-06-19 17:22:28 +02:00
# .env aus dem Projektroot laden (nur falls Variable nicht schon im Shell-Env gesetzt)
[ -f .env ] && source .env
2026-06-18 17:27:42 +02:00
MODEL="${QWEN3_TTS_MODEL:-Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice}"
strip_ansi() { sed 's/\x1b\[[0-9;]*[mK]//g'; }
t0=$SECONDS
# --- Gegenseitigen Service stoppen ---
printf "Clone-Container stoppt..."
docker compose --profile clone stop qwen3-tts-clone >/dev/null 2>&1 || true
2026-06-19 17:22:28 +02:00
docker compose --profile clone rm -f qwen3-tts-clone >/dev/null 2>&1 || true
2026-06-18 17:27:42 +02:00
printf " [%ds]
" $(( SECONDS - t0 ))
# --- Container starten ---
printf "TTS-Container startet..."
2026-06-19 17:22:28 +02:00
docker compose up -d qwen3-tts &>/tmp/qwen3-tts-compose.log
2026-06-18 17:27:42 +02:00
printf " [%ds]\n" $(( SECONDS - t0 ))
printf " Modell %s\n\n" "$MODEL"
# --- Log-Events im Hintergrund parsen und ausgeben ---
docker logs -f qwen3-tts 2>&1 | strip_ansi | while IFS= read -r line; do
case "$line" in
*"Stage 0 engine launch started"*)
printf " Stage 0 Talker LLM wird geladen\n" ;;
*"Initializing a V1 LLM engine"*)
printf " Stage 0 Engine initialisiert\n" ;;
*"Loading weights"*)
printf " Stage 0 Modell-Gewichte werden geladen...\n" ;;
*"Loading model weights took"*)
took=$(echo "$line" | grep -oP '\d+\.\d+s' | head -1)
printf " Stage 0 Gewichte geladen (%s)\n" "$took" ;;
*"Stage 1 engine launch started"*)
printf " Stage 1 Code2Wav Decoder wird geladen\n" ;;
*"Graph capturing finished"*)
printf " CUDA Graphen kompiliert\n" ;;
*"Application startup complete"*)
printf " Server FastAPI bereit\n" ;;
*"Uvicorn running on"*)
printf " Server HTTP läuft auf Port 8091\n" ;;
*"warmup] Server gesund"*)
printf " Warmup Aufwärm-Request läuft (kompiliert/lädt Graphen)...\n" ;;
*"warmup] fertig"*)
took=$(echo "$line" | grep -oP '\d+s' | head -1)
printf " Warmup Server ist heiß (%s)\n" "$took" ;;
*"ERROR"*|*"ValueError"*)
msg=$(echo "$line" | grep -oP '(ERROR|ValueError).*' | head -1)
printf " [!] %s\n" "${msg:0:100}" ;;
esac
done &
LOG_PID=$!
# --- Health-Check-Schleife ---
while (( SECONDS - t0 < MAX_WAIT )); do
if curl -sf "$HEALTH_URL" >/dev/null 2>&1; then
kill "$LOG_PID" 2>/dev/null
wait "$LOG_PID" 2>/dev/null || true
printf "\n✓ Bereit: API http://localhost:8091 UI http://localhost:8092 WS-Log ws://localhost:8094/v1/audio/speech/stream [%ds]\n" $(( SECONDS - t0 ))
exit 0
fi
# Abbruch wenn Container schon gestoppt ist
if ! docker ps --filter "name=qwen3-tts" --filter "status=running" -q | grep -q .; then
kill "$LOG_PID" 2>/dev/null
printf "\n✗ Container abgestürzt. Logs:\n"
docker logs --tail=20 qwen3-tts 2>&1 | strip_ansi | grep -E "ERROR|ValueError|Exception" | head -5
exit 1
fi
sleep 2
done
kill "$LOG_PID" 2>/dev/null
printf "\n✗ Timeout nach %ds. Logs: docker logs qwen3-tts\n" "$MAX_WAIT" >&2
exit 1