Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created June 4, 2012 21:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larzconwell/2870863 to your computer and use it in GitHub Desktop.
Save larzconwell/2870863 to your computer and use it in GitHub Desktop.
Convert pdf to text and read it out loud
#!/bin/bash
if [[ "$1" != "" ]]; then
pdf_file="$1"
shift
rm /tmp/pdf_file.txt >> /dev/null 2>&1
if [[ ! -f $(which pdftotext) ]]; then
echo "You do not have xpdf installed, please install it to convert pdfs to text..."
exit 1
fi
pdftotext "$@" "$pdf_file" /tmp/pdf_file.txt >> /dev/null 2>&1 | echo "Converting $pdf_file..."
if [[ -f "/tmp/pdf_file.txt" ]]; then
echo -n "Would you like to be read the output using espeak?"
read -t 10 read_pdf
if [[ "$read_pdf" == "yes" ]] || [[ "$read_pdf" == "y" ]]; then
clear
if [[ -f $(which espeak-gui) ]]; then
espeak-gui /tmp/pdf_file.txt >> /dev/null 2>&1
elif [[ -f $(which espeak) ]]; then
espeak -f /tmp/pdf_file.txt >> /dev/null 2>&1
else
# Assume OS X because most Linux distros have espeak installed by default
say -f /tmp/pdf_file.txt >> /dev/null 2>&1
fi
else
clear
cat /tmp/pdf_file.txt | less
fi
else
echo "There was an error while converting to text..."
exit 1
fi
else
echo "Nothing to read..."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment