Pico TTS, or: How to get your PC to read your PDFs to you

When faced with having to read a large book, my eyes can get very strained, forcing me to rest, though my brain remains awake enough to work. This is especially true for non-recreational (read: work) purposes,  when I do not have the liberty of reading slowly.

Tasked with reading a 200-page e-book in one day, I set about finding if there was any way I could get an audio copy of that same text. When I found no ready-made way to read aloud PDFs, I set about concocting my own (half-baked) solution.

So far, the best text to speech tool I’ve run across is Pico TTS, which is coincidentally the same tool that is used to provide Android’s text to speech. It is far better than the bundled Linux TTS tools, and on Debian/Ubuntu, it’s easily installed:

sudo apt-get install libttspico-utils

Ubuntu comes bundled with  `pdftotext`, a tool which strips out the raw text from PDFs and dumps it into a file.  Armed with my TTS engine and my PDF conversion tool, I was ready to begin my audio book. My solution? A simple shell-script which converts the PDF into text, then reads that text in 10-line chunks (to prevent creating a *huge* .wav file) via Pico TTS’s `pico2wav`:

#!/bin/bash

trap ctrl_c INT

function ctrl_c() {
    echo "Caught quit signal, exiting"
    exit 1
}

if [ ! -e unread.out ]; then
     pdftotext $1 output.txt
     cp output.txt unread.out
     #cp $1 unread.out
fi

text=""
while read p; do
    i=$(($i+1))
    text="$text $p"
    if [ $i -eq 10 ]; then
        i=0
        pico2wave -w=out.wav "$text"
        #mplayer -speed 1.5 -af scaletempo out.wav \ 
        #</dev/null >/dev/null
        aplay out.wav
        echo $text >> read.out
        echo $text > lastline.out
        sed -i -e 1,10d unread.out
        text=""
    fi
done <unread.out

pico2wave -w=out.wav "$text"
#mplayer -speed 1.5 -af scaletempo out.wav </dev/null >/dev/null
aplay out.wav

Well, that’s about it – just a little wrapper around a neat TTS tool. Note that you can uncomment the `mplayer` lines instead of using `aplay`, in order to increase audio playback to 1.5x normal speech speed. Note also that unread, read, and the last line read are all tracked — Control-C’ing out of the script will save your position to resume later.

Now, back to finishing that book…

One thought on “Pico TTS, or: How to get your PC to read your PDFs to you

Leave a Reply

Your email address will not be published. Required fields are marked *