#!/usr/bin/env bash

# https://aur.archlinux.org/packages/piper-tts-bin#comment-939482

VOICES_PATH="/usr/share/piper-voices"

if [[ ${VOICE: -3} = low ]]; then
 RATE=16000
else
 RATE=22050
fi

if which pw-play >/dev/null; then
 PLAY_APPS="pw-play --rate $RATE --channel-map LE -"
else
 PLAY_APPS="aplay -r $RATE -f S16_LE -t raw -"
fi

printf %s "$DATA" | piper-tts --model "$VOICES_PATH/$VOICE.onnx" -f - | $PLAY_APPS

wait
