#!/bin/bash -f
#
# PODNAME: awspollymp3
# ABSTRACT: script converting textfile named $1
# into mp3file $2
# with engine:voice $3
# using AWS Polly
# Check arguments
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <input_text_file> <output_mp3_file> <engine:voice>"
exit 1
fi
# Settings and validate engine and voice
SETTINGS=(${3//:/ })
if [ -z "$SETTINGS[0]" ] || [ -z "$SETTINGS[1]" ]; then
echo "Invalid engine or voice format. Use <engine:voice>."
exit 1
fi
# Run polly, run!
exec aws polly synthesize-speech --output-format mp3 \
--engine ${SETTINGS[0]} --voice-id ${SETTINGS[1]} \
--text "`cat $1`" $2 > /dev/null