2015-08-14 21:27:47 +02:00
#!/bin/sh
2016-04-20 00:52:22 +02:00
set -e -u
2015-06-13 01:03:31 +02:00
2016-04-20 00:52:22 +02:00
SCRIPTNAME=termux-tts-speak
2015-06-13 01:03:31 +02:00
show_usage () {
2016-09-04 16:48:47 +02:00
echo "Usage: $SCRIPTNAME [-e engine] [-l language] [-n region] [-v variant] [-p pitch] [-r rate] [-s stream] [text-to-speak]"
2016-04-26 01:37:45 +02:00
echo "Speak text with a system text-to-speech (TTS) engine. The text to speak is either supplied as arguments or read from stdin if no arguments are given."
echo " -e engine TTS engine to use (see termux-tts-engines)"
echo " -l language language to speak in (may be unsupported by the engine)"
2016-09-04 16:48:47 +02:00
echo " -n region region of language to speak in"
echo " -v variant variant of the language to speak in"
2016-04-26 01:37:45 +02:00
echo " -p pitch pitch to use in speech. 1.0 is the normal pitch,"
echo " lower values lower the tone of the synthesized voice,"
echo " greater values increase it."
echo " -r rate speech rate to use. 1.0 is the normal speech rate,"
echo " lower values slow down the speech"
echo " (0.5 is half the normal speech rate)"
echo " while greater values accelerates it"
echo " (2.0 is twice the normal speech rate)."
echo " -s stream audio stream to use (default:NOTIFICATION), one of:"
echo " ALARM, MUSIC, NOTIFICATION, RING, SYSTEM, VOICE_CALL"
exit 0
2015-06-13 01:03:31 +02:00
}
2016-04-20 00:52:22 +02:00
PARAMS=""
2016-09-04 16:48:47 +02:00
while getopts :he:l:n:v:p:r:s: option
2016-04-20 00:52:22 +02:00
do
2016-04-26 01:37:45 +02:00
case "$option" in
h) show_usage;;
e) PARAMS="$PARAMS --es engine $OPTARG";;
l) PARAMS="$PARAMS --es language $OPTARG";;
2016-09-04 16:48:47 +02:00
n) PARAMS="$PARAMS --es region $OPTARG";;
v) PARAMS="$PARAMS --es variant $OPTARG";;
2016-04-26 01:37:45 +02:00
p) PARAMS="$PARAMS --ef pitch $OPTARG";;
r) PARAMS="$PARAMS --ef rate $OPTARG";;
s) PARAMS="$PARAMS --es stream $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
2015-06-13 01:03:31 +02:00
done
2016-04-20 00:52:22 +02:00
shift $(($OPTIND-1))
CMD="@TERMUX_API@ TextToSpeech $PARAMS"
if [ $# = 0 ]; then
2016-04-26 01:37:45 +02:00
$CMD
2016-04-20 00:52:22 +02:00
else
2016-04-26 01:37:45 +02:00
echo $@ | $CMD
2016-04-20 00:52:22 +02:00
fi
2015-06-13 01:03:31 +02:00