DeutschLernen/scripts/ai-setup/download-coqui-model.sh
Lasse Rune Hansen e598d0cfa6 feat(backend/ai-setup): Phase 3 - Model download automation scripts
Phase 3 Tasks Completed:
- Download and configure vosk-model-de-0.22 (~500MB)
- Download and configure Coqui German model (~1.5GB)

Added setup automation scripts:
- scripts/ai-setup/download-vosk-model.sh - Downloads and extracts Vosk German model
- scripts/ai-setup/download-coqui-model.sh - Installs Coqui TTS and pre-downloads model
- scripts/ai-setup/setup-ai-models.sh - Master script for all AI model setup
- scripts/ai-setup/README.md - Comprehensive setup documentation

Added validation to services:
- VoskService: Validates ModelPath exists on startup
- TtsService: Validates all configuration on startup

Both scripts include:
- System requirement checks (wget, unzip, Python 3.8+)
- Color-coded output for better UX
- Error handling with helpful messages
- Verification steps
- Configuration examples

Build: Success
Tests: 296 passing (148 unit + 148 integration)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 10:57:08 +02:00

131 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
# =============================================================================
# Coqui TTS German Model Setup Script
# =============================================================================
# This script sets up Coqui TTS with a German model for text-to-speech.
#
# Requirements:
# - Python 3.8+
# - pip
# - ~1.5GB free disk space (for model download)
#
# Note: Coqui TTS will automatically download the model on first use.
# This script pre-downloads the model and verifies the setup.
#
# Usage:
# ./download-coqui-model.sh [model-name] [audio-storage-path]
#
# Example:
# ./download-coqui-model.sh
# ./download-coqui-model.sh tts_models/de/deu/fairseq/vits ./tmp/tts-audio
# =============================================================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
DEFAULT_MODEL="tts_models/de/deu/fairseq/vits"
DEFAULT_AUDIO_PATH="./tmp/tts-audio"
# Parse arguments
MODEL_NAME="${1:-$DEFAULT_MODEL}"
AUDIO_PATH="${2:-$DEFAULT_AUDIO_PATH}"
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
echo "=========================================="
echo "Coqui TTS German Model Setup"
echo "=========================================="
echo ""
# Check Python version
print_status "Checking Python version..."
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}' | cut -d. -f1-2)
if [ "$(printf '%s\n%s' "$PYTHON_VERSION" "3.8" | sort -V | head -n1)" != "3.8" ]; then
print_error "Python 3.8 or higher is required. Found: ${PYTHON_VERSION}"
exit 1
fi
print_success "Python ${PYTHON_VERSION} detected"
# Check pip
if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then
print_error "pip is not installed. Please install it first."
exit 1
fi
# Install Coqui TTS
print_status "Installing Coqui TTS..."
print_status "This may take several minutes..."
pip install TTS
print_success "Coqui TTS installed successfully!"
# Create audio storage directory
print_status "Creating audio storage directory: ${AUDIO_PATH}"
mkdir -p "${AUDIO_PATH}"
print_success "Audio storage directory created"
# Pre-download the model (optional but recommended)
print_status "Pre-downloading German model: ${MODEL_NAME}"
print_status "This will download ~1.5GB of data..."
print_status "(This step is optional - model will download automatically on first use)"
# Test model loading to trigger download
python3 -c "
from TTS.api import TTS
import sys
try:
tts = TTS(model_name='${MODEL_NAME}')
print('Model loaded successfully')
sys.exit(0)
except Exception as e:
print(f'Note: Model will download on first use. Error: {e}')
sys.exit(0)
"
print_success "Coqui TTS setup complete!"
echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
print_success "Coqui TTS with model ${MODEL_NAME} is ready"
echo ""
print_status "Configuration for appsettings.json:"
echo "{"
echo " \"Coqui\": {"
echo " \"PythonPath\": \"python3\","
echo " \"ModelName\": \"${MODEL_NAME}\","
echo " \"OutputFormat\": \"wav\","
echo " \"SampleRate\": 22050,"
echo " \"AudioStoragePath\": \"${AUDIO_PATH}\","
echo " \"MaxTextLength\": 5000,"
echo " \"TimeoutSeconds\": 60"
echo " }"
echo "}"
echo ""
print_status "Verify with:"
print_status " python3 -c \"from TTS.api import TTS; tts = TTS(model_name='${MODEL_NAME}'); tts.tts_to_file(text='Hallo', file_path='/tmp/test.wav'); print('OK')\""
echo ""