pico2audio 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. usage() {
  3. SELF="$( basename $0 )"
  4. INDT="$( echo $SELF | sed 's,., ,g' )"
  5. cat <<EOF
  6. $SELF - wrapper for pico2wave, renders text to speech and
  7. $INDT plays it using the 'play' command.
  8. Written by B. Watson <urchlay@slackware.uk>, for the SlackBuilds.org project.
  9. Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
  10. If a -l <language> option is given, it will be passed to pico2wave.
  11. Exit status of $SELF is that of pico2wave.
  12. Examples:
  13. $SELF 'Hello world.'
  14. Speaks "Hello world" in the default language (en-US).
  15. $SELF -l en-GB 'Hello world.'
  16. As above, in a British accent.
  17. fortune -s | $SELF
  18. Reads from standard input.
  19. $SELF < /etc/motd
  20. Speak a text file. Don't forget the < or it says the filename instead.
  21. EOF
  22. }
  23. # main()
  24. case "$1" in
  25. '-?'|-h|-help|--help)
  26. usage
  27. exit 0
  28. ;;
  29. -l) LOPT="$1 $2"
  30. shift
  31. if [ -z "$1" ]; then
  32. echo "$(basename $0): missing argument to -l option" 1>&2
  33. exit 1
  34. fi
  35. shift
  36. ;;
  37. -l?*) LOPT="$1"
  38. shift
  39. ;;
  40. esac
  41. which pico2wave >/dev/null || exit 1
  42. which play >/dev/null || exit 1
  43. DIR=$( mktemp -t -d pico2audio.XXXXXX )
  44. if [ ! -d "$DIR" ]; then
  45. exit 1 # mktemp already printed an error message
  46. fi
  47. # the actual pico2wave command accepts multiple word arguments,
  48. # but only speaks the first one (silently ignores the rest).
  49. # here we combine all the word args into one quoted string and
  50. # pass it to pico2wave via eval, so it sees one argument, possibly
  51. # with spaces.
  52. [ -n "$*" ] && ARGS="\"$@\""
  53. eval pico2wave $LOPT -w $DIR/tmp.wav $ARGS
  54. E="$?"
  55. play -q $DIR/tmp.wav 2>/dev/null
  56. rm -rf $DIR
  57. exit "$E"