#!/bin/bash
# A small handy script to be able to read PDF files via festival
# In order to properly work this script requires
# working installation of the programs:
# pdftotext and festival
# This script is licensed under GNU GPL version 2
# Check out the license on http://gnu.org/licenses/gpl2.txt
trap if_int INT;

# path to pdftotext and festival
pdftotext=$(which pdftotext)
festival=$(which festival);
arg1="$1";
new_name=$(echo $arg1 |sed -e "s#pdf#txt#gi");
tmp_file="/tmp/$new_name";

 if_int () {
 # bye bye galaxy :]
 rm -f "$tmp_file"
 exit 0;
 }


if [ "$arg1" != "" ]; then
if [ "$pdftotext" ]; then
$pdftotext "$arg1" "$tmp_file";
echo "Playing file $i";
cat /tmp/$new_name | $festival --tts;
rm -f $tmp_file;
fi
else
echo "Missing [file] argument";
exit 1;
fi
