#!/usr/bin/env bash
# Transcribe any audio file (Telegram .oga voice notes included) to text on stdout.
# Uses the small model: ~30s for a 20s note on this 2-core box (turbo-q5 took ~1m40s).
# For max Arabic accuracy on an idle box: MODEL=large-v3-turbo-q5_0 transcribe.sh <file>
set -euo pipefail
f="$1"
MODEL="${MODEL:-small}"
wav=$(mktemp /tmp/transcribe-XXXXXX.wav)
trap "rm -f \"$wav\"" EXIT
ffmpeg -y -loglevel error -i "$f" -ar 16000 -ac 1 "$wav"
/root/tools/whisper.cpp/build/bin/whisper-cli \
  -m "/root/tools/whisper.cpp/models/ggml-${MODEL}.bin" \
  -f "$wav" -l auto -t 2 -bs 1 -nt --no-prints 2>/dev/null
