● Zion Boggan
repos/Zion Pm/archive/old-conductor-sketch/bin/intake-voice.sh
zionboggan.com ↗
29 lines · bash
History for this file →
1
set -uo pipefail
2
PM="/shared/projects/zion-pm"
3
VOICE="$PM/inbox/voice"; DONE="$VOICE/processed"
4
STT="${PM_STT_URL:-http://REDACTED-IP:8770/v1/audio/transcriptions}"
5
MODEL="${PM_STT_MODEL:-large-v3-turbo}"
6
mkdir -p "$VOICE" "$DONE"
7
 
8
shopt -s nullglob
9
files=("$VOICE"/*.{m4a,mp3,wav,ogg,flac,aac})
10
[ "${#files[@]}" -eq 0 ] && { echo "[intake-voice] no audio in $VOICE"; exit 0; }
11
 
12
for f in "${files[@]}"; do
13
  echo "[intake-voice] transcribing $(basename "$f")"
14
  TXT=$(curl -s -m 180 "$STT" -F "file=@$f" -F "model=$MODEL" -F "response_format=text" 2>/dev/null)
15
  TXT=$(printf '%s' "$TXT" | tr '\n' ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
16
  if [ -z "$TXT" ]; then
17
    echo "  -> empty transcript (STT down? check the sidecar). Leaving file in place."
18
    continue
19
  fi
20
  echo "  -> \"$TXT\""
21
  bash "$PM/bin/pm" add "$TXT" --type misc >/dev/null
22
  python3 - "$PM/state/activity.jsonl" "$(basename "$f")" "$TXT" <<'PY'
23
import json,sys,time
24
path,fn,txt=sys.argv[1:4]
25
open(path,"a").write(json.dumps({"ts":time.strftime("%Y-%m-%dT%H:%M:%S"),"event":"intake_voice","file":fn,"text":txt[:120]})+"\n")
26
PY
27
  mv "$f" "$DONE/"
28
done
29
echo "[intake-voice] done"