#!/usr/bin/env bash # Pocket-TTS voice generator + sender # Usage: voice.sh "text" [voice] [format] # Output: path to generated audio file (for chaining) TTS_URL="https://hf4uwho-pocket-tts.hf.space/tts" TEXT="${1:?Usage: voice.sh 'text' [voice] [format]}" VOICE="${2:-af_alloy}" FORMAT="${3:-ogg}" OUTDIR="/tmp/tts" mkdir -p "$OUTDIR" # Unique filename HASH=$(echo -n "$TEXT$VOICE$(date +%s%N)" | md5sum | cut -c1-12) OUTFILE="$OUTDIR/voice_${HASH}.${FORMAT}" # Generate HTTP_CODE=$(curl -s -w "%{http_code}" -o "$OUTFILE" "${TTS_URL}?text=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$TEXT'''))")&voice=${VOICE}&format=${FORMAT}" 2>/dev/null) if [ "$HTTP_CODE" != "200" ]; then echo "ERROR: HTTP $HTTP_CODE" >&2 rm -f "$OUTFILE" exit 1 fi # Verify it's actual audio MIME=$(file -b --mime-type "$OUTFILE" 2>/dev/null) if [[ "$MIME" != audio/* ]] && [[ "$MIME" != application/ogg ]]; then echo "ERROR: Not audio (got $MIME)" >&2 cat "$OUTFILE" >&2 rm -f "$OUTFILE" exit 1 fi echo "$OUTFILE"