| 1 | #!/bin/sh |
| 2 | set -e -u |
| 3 | |
| 4 | SCRIPTNAME=termux-tts-speak |
| 5 | show_usage () { |
| 6 | echo "Usage: $SCRIPTNAME [-e engine] [-l language] [-n region] [-v variant] [-p pitch] [-r rate] [-s stream] [text-to-speak]" |
| 7 | 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." |
| 8 | echo " -e engine TTS engine to use (see termux-tts-engines)" |
| 9 | echo " -l language language to speak in (may be unsupported by the engine)" |
| 10 | echo " -n region region of language to speak in" |
| 11 | echo " -v variant variant of the language to speak in" |
| 12 | echo " -p pitch pitch to use in speech. 1.0 is the normal pitch," |
| 13 | echo " lower values lower the tone of the synthesized voice," |
| 14 | echo " greater values increase it." |
| 15 | echo " -r rate speech rate to use. 1.0 is the normal speech rate," |
| 16 | echo " lower values slow down the speech" |
| 17 | echo " (0.5 is half the normal speech rate)" |
| 18 | echo " while greater values accelerates it" |
| 19 | echo " (2.0 is twice the normal speech rate)." |
| 20 | echo " -s stream audio stream to use (default:NOTIFICATION), one of:" |
| 21 | echo " ALARM, MUSIC, NOTIFICATION, RING, SYSTEM, VOICE_CALL" |
| 22 | exit 0 |
| 23 | } |
| 24 | |
| 25 | PARAMS="" |
| 26 | |
| 27 | while getopts :he:l:n:v:p:r:s: option |
| 28 | do |
| 29 | case "$option" in |
| 30 | h) show_usage;; |
| 31 | e) PARAMS="$PARAMS --es engine $OPTARG";; |
| 32 | l) PARAMS="$PARAMS --es language $OPTARG";; |
| 33 | n) PARAMS="$PARAMS --es region $OPTARG";; |
| 34 | v) PARAMS="$PARAMS --es variant $OPTARG";; |
| 35 | p) PARAMS="$PARAMS --ef pitch $OPTARG";; |
| 36 | r) PARAMS="$PARAMS --ef rate $OPTARG";; |
| 37 | s) PARAMS="$PARAMS --es stream $OPTARG";; |
| 38 | ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; |
| 39 | esac |
| 40 | done |
| 41 | shift $(($OPTIND-1)) |
| 42 | |
| 43 | CMD="@TERMUX_API@ TextToSpeech $PARAMS" |
| 44 | if [ $# = 0 ]; then |
| 45 | $CMD |
| 46 | else |
| 47 | echo $@ | $CMD |
| 48 | fi |
| 49 | |