← back to Dear Bubbe Nextjs
scripts/voice-monitor.sh
68 lines
#!/bin/bash
# Voice Feature Monitoring Script for Dear Bubbe
# Location: /root/Projects/dear-bubbe-nextjs/scripts/voice-monitor.sh
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
MONITOR_LOG="/root/Projects/dear-bubbe-nextjs/voice-monitor.log"
echo "[$TIMESTAMP] Starting voice feature monitoring..." >> $MONITOR_LOG
# Test different voice modes
VOICE_MODES=("bubbe" "meshugana" "comedian")
SUCCESS_COUNT=0
TOTAL_TESTS=0
for mode in "${VOICE_MODES[@]}"; do
echo "[$TIMESTAMP] Testing $mode voice mode..." >> $MONITOR_LOG
# Test voice synthesis
RESPONSE=$(curl -s --max-time 30 -w "%{http_code}" \
http://45.61.58.125:3011/api/bubbe-voice \
-H "Content-Type: application/json" \
-d "{\"text\":\"Testing $mode voice mode for monitoring\",\"mode\":\"$mode\"}" \
-o "/tmp/voice_test_$mode.mp3")
((TOTAL_TESTS++))
if [ "$RESPONSE" = "200" ] && [ -f "/tmp/voice_test_$mode.mp3" ] && [ -s "/tmp/voice_test_$mode.mp3" ]; then
AUDIO_SIZE=$(stat -c%s "/tmp/voice_test_$mode.mp3")
echo "[$TIMESTAMP] ✅ $mode voice: SUCCESS (size: $AUDIO_SIZE bytes)" >> $MONITOR_LOG
((SUCCESS_COUNT++))
rm -f "/tmp/voice_test_$mode.mp3"
else
echo "[$TIMESTAMP] ❌ $mode voice: FAILED (HTTP: $RESPONSE)" >> $MONITOR_LOG
# Log recent API errors for this failure
echo "[$TIMESTAMP] Recent errors for debugging:" >> $MONITOR_LOG
pm2 logs bubbe-ai --lines 20 --err | tail -5 >> $MONITOR_LOG 2>/dev/null || echo "No recent errors found" >> $MONITOR_LOG
fi
done
# Calculate success rate
SUCCESS_RATE=$((SUCCESS_COUNT * 100 / TOTAL_TESTS))
echo "[$TIMESTAMP] Voice monitoring completed: $SUCCESS_COUNT/$TOTAL_TESTS successful ($SUCCESS_RATE%)" >> $MONITOR_LOG
# Alert if success rate is low
if [ $SUCCESS_RATE -lt 80 ]; then
echo "[$TIMESTAMP] ⚠️ ALERT: Voice feature success rate below 80% ($SUCCESS_RATE%)" >> $MONITOR_LOG
# Check ElevenLabs API status
ELEVENLABS_STATUS=$(curl -s --max-time 10 -w "%{http_code}" "https://api.elevenlabs.io/v1/voices" \
-H "xi-api-key: ${ELEVENLABS_API_KEY:-}" \
-o /dev/null)
echo "[$TIMESTAMP] ElevenLabs API status check: HTTP $ELEVENLABS_STATUS" >> $MONITOR_LOG
fi
echo "[$TIMESTAMP] Voice monitoring session completed" >> $MONITOR_LOG
echo "" >> $MONITOR_LOG
# Return appropriate exit code
if [ $SUCCESS_RATE -eq 100 ]; then
exit 0
elif [ $SUCCESS_RATE -ge 80 ]; then
exit 1
else
exit 2
fi