Linux command line Text to Speach Reader that you can listen to

SetvirSetvir wrote 04/03/2015 at 08:03 • 2 min read • Like

Herewith a Linux command line Gutenberg Press text to speech reader that is free to use and does not sound to horrible: ;-)

You can also follow along while it is read.

The script below gets rid of all the extra line breaks while text is being read. It takes everything before reading and converts it to lowercase letters forcing the reader to read uppercase words in the text file instead of spelling them.

You can edit the script to remove any unwanted characters that make listening to a text reader a pain.

Downside - the script does not allow you to jump to sections or "page" through the book - it starts at the beginning and ends when finished... Should not be difficult to implement a counter that saves where you were and then automatically continues where you left off...

Installing whats needed:
Before use install pico2wave using the following:

sudo apt-get install libttspico0 libttspico-utils libttspico-data

and then follow the instructions and install picospeaker sript:

The command line script to use reader with Gutenberg Press text files:

sed ':a;N;$!ba;s/\n\r/@/g' alice.txt | sed ':a;N;$!ba;s/\r\n/ /g' | sed ':a;N;$!ba;s/@/\n\r/g' | sed ':a;N;$!ba;s/_//g' | sed ':a;N;$!ba;s/\[/(/g' | sed ':a;N;$!ba;s/\]/)/g'  | while read line; do clear; echo "$line"; echo "$line" | sed 's/--/,, /g' | awk {'print tolower($_)'} | picospeaker -v 0.5 -r -15 -p 0 ; done

1. Download a text book from Gutenberg Press and save it to a directory.

2. Open the directory in a terminal and copy and paste the above script to the command line.

3. Substitute "alice.txt" with the name of the text file you want to read. Press enter ;-)

Sit back and relax while your computer reads the book to you. And if you want to, read along...

NOTE: Please be fair, I am not a Linux guru and the script above was hacked together by trial and error from pieces all over the internet, your input on streamlining code will be appreciated ...



Setvir wrote 04/17/2015 at 16:26 point

Variation on the above script for pdf to speech (with line count and ability to start where you previously ended):

count = 0; pdftotext -layout Downloads/101.pdf - | awk ' /^$/ { print; } /./ { printf("%s ", $0); }' | while read line; do clear; echo "Count: $count"; if [  $count -ge 0 ]; then echo "$line"; picospeaker -v 0.5 -r -18 -p -3 "$line";fi;  let count=count+1; done

A count number is displayed as the document is read. Stop reading by pressing ctrl-z.

Then when you want to continue just change the zero in the   '$count -ge 0' part of the script to the count you were at last.

NOTE: needs pdftotext installed.

  Are you sure? yes | no