aboutsummaryrefslogtreecommitdiff
path: root/accessibility/svox/pico2audio
blob: 673950eb838c97080a6000b110f7b4d839452114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh

usage() {
  SELF="$( basename $0 )"
  INDT="$( echo $SELF | sed 's,., ,g' )"
  cat <<EOF
$SELF - wrapper for pico2wave, renders text to speech and
$INDT   plays it using the 'play' command.

Written by B. Watson <yalhcru@gmail.com>, for the SlackBuilds.org project.
Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

If a -l <language> option is given, it will be passed to pico2wave.

Exit status of $SELF is that of pico2wave.

Examples:

  $SELF 'Hello world.'
    Speaks "Hello world" in the default language (en-US).

  $SELF -l en-GB 'Hello world.'
    As above, in a British accent.

  fortune -s | $SELF
    Reads from standard input.

  $SELF < /etc/motd
    Speak a text file. Don't forget the < or it says the filename instead.
EOF
}

# main()

case "$1" in
  '-?'|-h|-help|--help)
        usage
        exit 0
        ;;
  -l)   LOPT="$1 $2"
        shift
        if [ -z "$1" ]; then
          echo "$(basename $0): missing argument to -l option" 1>&2
          exit 1
        fi
        shift
        ;;
  -l?*) LOPT="$1"
        shift
        ;;
esac

which pico2wave >/dev/null || exit 1
which play      >/dev/null || exit 1

DIR=$( mktemp -t -d pico2audio.XXXXXX )
if [ ! -d "$DIR" ]; then
  exit 1 # mktemp already printed an error message
fi

# the actual pico2wave command accepts multiple word arguments,
# but only speaks the first one (silently ignores the rest).
# here we combine all the word args into one quoted string and
# pass it to pico2wave via eval, so it sees one argument, possibly
# with spaces.
[ -n "$*" ] && ARGS="\"$@\""

eval pico2wave $LOPT -w $DIR/tmp.wav $ARGS
E="$?"
play -q $DIR/tmp.wav 2>/dev/null
rm -rf $DIR
exit "$E"