#!/usr/bin/env bash
# scripts/manual/audio-mic-fetch.sh
#
# Manual: fetch and play recent microphone uplink clips during field debugging.
# Not part of CI; requires SSH access to the target server.
set -euo pipefail

PI_HOST="nikto@192.168.42.253"   # adjust if needed
REMOTE_DIR="/tmp"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT

scp -q "${PI_HOST}:${REMOTE_DIR}/voice-*.aac" "$TMPDIR/" 2>/dev/null \
  || { echo "❌  no mic clip files found yet"; exit 1; }

LATEST=$(ls -1t "$TMPDIR"/voice-*.aac | head -n1)
echo "🎤 playing $(basename "$LATEST") ..."
gst-play-1.0 --quiet "$LATEST"
