| 1 | #!/bin/sh |
| 2 | set -e -u |
| 3 | |
| 4 | SCRIPTNAME=termux-tts-speak |
| 5 | show_usage () { |
| 6 | echo "Usage: $SCRIPTNAME [OPTIONS] <text-to-speak>" |
| 7 | echo "Speak stdin input with a system text-to-speech (TTS) engine." |
| 8 | echo "" |
| 9 | echo " -e <engine> TTS engine to use (see 'termux-tts-engines')" |
| 10 | echo " -l <language> language to speak in (may be unsupported by the engine)" |
| 11 | echo " -p <pitch> pitch to use in speech. 1.0 is the normal pitch," |
| 12 | echo " lower values lower the tone of the synthesized voice," |
| 13 | echo " greater values increase it." |
| 14 | echo " -r <rate> speech rate to use. 1.0 is the normal speech rate," |
| 15 | echo " lower values slow down the speech (0.5 is half the normal speech rate)," |
| 16 | echo " greater values accelerate it ({@code 2.0} is twice the normal speech rate)." |
| 17 | echo "" |
| 18 | echo "The text to send can be specified either as arguments or on stdin if no arguments are given." |
| 19 | exit 0 |
| 20 | } |
| 21 | |
| 22 | PARAMS="" |
| 23 | |
| 24 | while getopts :he:l:p:r: option |
| 25 | do |
| 26 | case "$option" in |
| 27 | h) show_usage;; |
| 28 | e) PARAMS="$PARAMS --es engine $OPTARG";; |
| 29 | l) PARAMS="$PARAMS --es language $OPTARG";; |
| 30 | p) PARAMS="$PARAMS --ef pitch $OPTARG";; |
| 31 | r) PARAMS="$PARAMS --ef rate $OPTARG";; |
| 32 | ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; |
| 33 | esac |
| 34 | done |
| 35 | shift $(($OPTIND-1)) |
| 36 | |
| 37 | CMD="@TERMUX_API@ TextToSpeech $PARAMS" |
| 38 | if [ $# = 0 ]; then |
| 39 | $CMD |
| 40 | else |
| 41 | echo $@ | $CMD |
| 42 | fi |
| 43 | |