#!/bin/bash
set -euo pipefail

# Usage: $0 filename.txt
# Result: filename.txt.opus

TXTFILE=$1
AUDFILE=$TXTFILE.opus

# cat txt | (piper inside podman) | (ffmpeg encodes to opus) > txt.opus
cat "$TXTFILE" \
| podman run \
	--rm -i \
	-v ~/work/projects/tts/piper-voices:/piper-voices:z \
	--entrypoint '["/usr/share/piper/piper", "--model", "/piper-voices/en/en_US/lessac/high/en_US-lessac-high.onnx", "--output_raw"]' \
	linuxserver/piper \
| ffmpeg -ar 22050 -ac 1 -f s16le -i - "$AUDFILE" -y
