X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/59f0d218a6ff34c80cf898f6d7ac62555ba8eb11..1acf7001f99a1b70813138081bd13fd35f54d2d0:/packages/termux-api/termux-tts-speak?ds=sidebyside diff --git a/packages/termux-api/termux-tts-speak b/packages/termux-api/termux-tts-speak index e7118aac..4d58f22a 100755 --- a/packages/termux-api/termux-tts-speak +++ b/packages/termux-api/termux-tts-speak @@ -1,34 +1,43 @@ -#!/system/bin/sh +#!/bin/sh +set -e -u -set -u - -PARAMS="" - -SCRIPTNAME=$0 +SCRIPTNAME=termux-tts-speak show_usage () { - echo "usage: $SCRIPTNAME [OPTIONS]" + echo "Usage: $SCRIPTNAME [OPTIONS] " + echo "Speak stdin input with a system text-to-speech (TTS) engine." + echo "" + echo " -e TTS engine to use (see 'termux-tts-engines')" + echo " -l language to speak in (may be unsupported by the engine)" + echo " -p 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 speech rate to use. 1.0 is the normal speech rate," + echo " lower values slow down the speech (0.5 is half the normal speech rate)," + echo " greater values accelerate it ({@code 2.0} is twice the normal speech rate)." echo "" - echo "Speak with a device text-to-speech (TTS) engine." - echo "Find out about valid options with the device-tts-engines program." - echo " -e, --engine TTS engine to use" - echo " -l, --language language to speak in (may be unsupported by the engine)" - echo " -p, --pitch pitch to use in speech" - echo " -r, --rate rate to use in speech" + echo "The text to send can be specified either as arguments or on stdin if no arguments are given." + exit 0 } -O=`busybox getopt -q -l engine: -l help -l language: -l pitch: -l rate: -- e:hl:p:r: "$@"` -if [ $? != 0 ] ; then show_usage; exit 1 ; fi -eval set -- "$O" -while true; do -case "$1" in - -e|--engine) PARAMS="$PARAMS --es engine $2"; shift 2;; - -l|--language) PARAMS="$PARAMS --es language $2"; shift 2;; - -p|--pitch) PARAMS="$PARAMS --ef pitch $2"; shift 2;; - -r|--rate) PARAMS="$PARAMS --ef rate $2"; shift 2;; - -h|--help) show_usage; exit 0;; - --) shift; break;; - *) echo Error; exit 1;; -esac +PARAMS="" + +while getopts :he:l:p:r: option +do + case "$option" in + h) show_usage;; + e) PARAMS="$PARAMS --es engine $OPTARG";; + l) PARAMS="$PARAMS --es language $OPTARG";; + p) PARAMS="$PARAMS --ef pitch $OPTARG";; + r) PARAMS="$PARAMS --ef rate $OPTARG";; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac done +shift $(($OPTIND-1)) + +CMD="@TERMUX_API@ TextToSpeech $PARAMS" +if [ $# = 0 ]; then + $CMD +else + echo $@ | $CMD +fi -termux-api SpeechReceiver $PARAMS