Skip to content

Instantly share code, notes, and snippets.

@sholtomaud
Forked from danilop/polly.sh
Created June 5, 2024 14:33
Show Gist options
  • Save sholtomaud/fd19b1472dac4f8f007925f061c7e42f to your computer and use it in GitHub Desktop.
Save sholtomaud/fd19b1472dac4f8f007925f061c7e42f to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
echo "Usage: $0 [-v <Ruth|Matthew|Amy>]" 1>&2
echo "Ruth : Female English (US) - Default" 1>&2
echo "Matthew : Male English (US)" 1>&2
echo "Amy : Female English (British)" 1>&2
exit
}
while getopts ":v:" OPT; do
case "${OPT}" in
v)
VOICE=${OPTARG}
[ "${VOICE}" = "Ruth" ] || [ "${VOICE}" = Matthew ] || [ "${VOICE}" = Amy ] || usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${VOICE}" ]; then
VOICE="Ruth"
fi
TMP_TEXT_FILE=$(mktemp)
cat > ${TMP_TEXT_FILE}
cat ${TMP_TEXT_FILE}
TMP_VOICE_FILE=$(mktemp)
echo "Using ${VOICE} voice."
aws polly synthesize-speech --output-format mp3 --region us-east-1 \
--text "$(cat ${TMP_TEXT_FILE})" \
--voice-id ${VOICE} --engine generative ${TMP_VOICE_FILE}
afplay ${TMP_VOICE_FILE}
rm ${TMP_TEXT_FILE} ${TMP_VOICE_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment