#!/bin/bash # Setup STT Service on Mac Mini # Creates launchd service for auto-start set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" STT_DIR="$REPO_DIR/services/mana-stt" PLIST_NAME="com.manacore.stt" PLIST_PATH="$HOME/Library/LaunchAgents/$PLIST_NAME.plist" echo "==============================================" echo " ManaCore STT Service Setup (Mac Mini)" echo "==============================================" echo "" # Check if STT service directory exists if [ ! -d "$STT_DIR" ]; then echo "Error: STT service directory not found at $STT_DIR" exit 1 fi # Run the main setup script first echo "1. Running STT service setup..." cd "$STT_DIR" if [ ! -d ".venv" ]; then echo " Installing dependencies..." ./setup.sh else echo " Virtual environment already exists" echo " Skipping dependency installation" fi # Create launchd plist echo "" echo "2. Creating launchd service..." cat > "$PLIST_PATH" << EOF Label $PLIST_NAME ProgramArguments $STT_DIR/.venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 3020 WorkingDirectory $STT_DIR EnvironmentVariables PATH /opt/homebrew/bin:$STT_DIR/.venv/bin:/usr/local/bin:/usr/bin:/bin PORT 3020 WHISPER_MODEL large-v3 PRELOAD_MODELS false CORS_ORIGINS https://mana.how,https://chat.mana.how,https://todo.mana.how RunAtLoad KeepAlive SuccessfulExit Crashed ThrottleInterval 10 StandardOutPath /tmp/manacore-stt.log StandardErrorPath /tmp/manacore-stt.error.log EOF echo " Created: $PLIST_PATH" # Unload if already loaded echo "" echo "3. Loading launchd service..." launchctl unload "$PLIST_PATH" 2>/dev/null || true launchctl load "$PLIST_PATH" # Wait for service to start sleep 2 # Check if service is running echo "" echo "4. Checking service status..." if launchctl list | grep -q "$PLIST_NAME"; then echo " Service is running" # Check health endpoint sleep 3 if curl -s http://localhost:3020/health > /dev/null 2>&1; then echo " Health check passed" HEALTH=$(curl -s http://localhost:3020/health) echo " $HEALTH" else echo " Warning: Health check failed (service may still be starting)" echo " Check logs: tail -f /tmp/manacore-stt.log" fi else echo " Warning: Service may not be running" echo " Check logs: tail -f /tmp/manacore-stt.error.log" fi echo "" echo "==============================================" echo " STT Service Setup Complete!" echo "==============================================" echo "" echo "Service URL: http://localhost:3020" echo "" echo "Useful commands:" echo " # View logs" echo " tail -f /tmp/manacore-stt.log" echo "" echo " # Restart service" echo " launchctl kickstart -k gui/\$(id -u)/$PLIST_NAME" echo "" echo " # Stop service" echo " launchctl unload $PLIST_PATH" echo "" echo " # Start service" echo " launchctl load $PLIST_PATH" echo "" echo " # Test transcription" echo " curl -X POST http://localhost:3020/transcribe \\" echo " -F 'file=@audio.mp3' \\" echo " -F 'language=de'" echo ""