#Requires -Version 5.1 <#! Chatterbox TTS - Windows setup script What it does: - Creates a Python virtual environment in .venv (if missing) - Upgrades pip - Installs dependencies from backend/requirements.txt and requirements.txt - Creates a default .env with sensible ports if not present - Launches start_servers.py using the venv's Python Usage: - Right-click this file and "Run with PowerShell" OR from PowerShell: ./setup-windows.ps1 - Optional flags: -NoInstall -> Skip installing dependencies (just start servers) -NoStart -> Prepare env but do not start servers Notes: - You may need to allow script execution once: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - Press Ctrl+C in the console to stop both servers. !#> param( [switch]$NoInstall, [switch]$NoStart ) $ErrorActionPreference = 'Stop' function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan } function Write-Ok($msg) { Write-Host "[ OK ] $msg" -ForegroundColor Green } function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow } function Write-Err($msg) { Write-Host "[FAIL] $msg" -ForegroundColor Red } $root = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $root $venvDir = Join-Path $root ".venv" $venvPython = Join-Path $venvDir "Scripts/python.exe" # 1) Ensure Python available function Get-BasePython { try { $pyExe = (Get-Command py -ErrorAction SilentlyContinue) if ($pyExe) { return 'py -3' } } catch { } try { $pyExe = (Get-Command python -ErrorAction SilentlyContinue) if ($pyExe) { return 'python' } } catch { } throw "Python not found. Please install Python 3.x and add it to PATH." } # 2) Create venv if missing if (-not (Test-Path $venvPython)) { Write-Info "Creating virtual environment in .venv" $basePy = Get-BasePython if ($basePy -eq 'py -3') { & py -3 -m venv .venv } else { & python -m venv .venv } Write-Ok "Virtual environment created" } else { Write-Info "Using existing virtual environment: $venvDir" } if (-not (Test-Path $venvPython)) { throw ".venv python not found at $venvPython" } # 3) Install dependencies if (-not $NoInstall) { Write-Info "Upgrading pip" & $venvPython -m pip install --upgrade pip # Backend requirements $backendReq = Join-Path $root 'backend/requirements.txt' if (Test-Path $backendReq) { Write-Info "Installing backend requirements" & $venvPython -m pip install -r $backendReq } else { Write-Warn "backend/requirements.txt not found" } # Root requirements (optional frontend / project libs) $rootReq = Join-Path $root 'requirements.txt' if (Test-Path $rootReq) { Write-Info "Installing root requirements" & $venvPython -m pip install -r $rootReq } else { Write-Warn "requirements.txt not found at repo root" } Write-Ok "Dependency installation complete" } # 4) Ensure .env exists with sensible defaults $envPath = Join-Path $root '.env' if (-not (Test-Path $envPath)) { Write-Info "Creating default .env" @( 'BACKEND_PORT=8000', 'BACKEND_HOST=127.0.0.1', 'FRONTEND_PORT=8001', 'FRONTEND_HOST=127.0.0.1' ) -join "`n" | Out-File -FilePath $envPath -Encoding utf8 -Force Write-Ok ".env created" } else { Write-Info ".env already exists; leaving as-is" } # 5) Start servers if ($NoStart) { Write-Info "-NoStart specified; setup complete. You can start later with:" Write-Host " `"$venvPython`" `"$root\start_servers.py`"" -ForegroundColor Gray exit 0 } Write-Info "Starting servers via start_servers.py" & $venvPython "$root/start_servers.py"