#!/bin/bash
# Makes the synthetic reads used in the podcast ad length test. macOS only (needs the say command).
# Usage: bash make-audio.sh <texts-folder> <output-folder>
set -euo pipefail
[ $# -eq 2 ] || { echo "usage: bash make-audio.sh <texts-folder> <output-folder>" >&2; exit 2; }
command -v say >/dev/null || { echo "say not found: this script needs macOS" >&2; exit 2; }
[ -d "$1" ] || { echo "texts folder not found: $1" >&2; exit 2; }
mkdir -p "$2"
for f in "$1"/*.txt; do
  base=$(basename "$f" .txt)
  # reader name | voice | rate option (empty = the voice default)
  while IFS='|' read -r name voice rate; do
    out="$2/${base}__${name}.aiff"
    if [ -n "$rate" ]; then say -v "$voice" -r "$rate" -f "$f" -o "$out"; else say -v "$voice" -f "$f" -o "$out"; fi
  done <<'READERS'
alex-r40|Alex|40
alex-r80|Alex|80
alex-r120|Alex|120
alex-default|Alex|
samantha-default|Samantha|
READERS
done
ls "$2" | wc -l
