#!/bin/sh
# BIG TODO: how to pause reading mid-file say? For really big texts? How to forward/backward/seek? :p
# TODO get global settings from /var/lib/shelli/say.cfg for speed, voice, volume maybe?
# -s <speed, words per minute> (optional)
# [<file>] - if first arg (after -s <n>) is a file, then read the file
# TODO not always producing sound, workaround is to call earpiece or speaker before hand?
if [ "$1" = "-s" ]; then
  SPEED="-s $2"
  shift 2
fi
if [ $# -gt 0 ]; then
  if [ -f "$1" ]; then
    espeak $SPEED -f "$1" --stdout | aplay --quiet --buffer-size=22050 -
  else
    echo "$@" | espeak $SPEED --stdout | aplay --quiet --buffer-size=22050 -
  fi
else
  while read line; do
    echo "$line" | espeak $SPEED --stdout | aplay --quiet --buffer-size=22050 -
  done
fi
