This one works in a console. Converts txt only but there are many methods of extracting txt from pdf.
I gave up the mbrola voices with espeak because at certain moment I realized they are less clear.
At first they seem to sound nicer and more natural, but later you come to a conclusion that pure espeak is definitely more clear and you can listen faster.
The problem with espeak+mbrola is that there are kind of micro-gaps between pronounced letters / words. The more I listened to it the less I liked it.
Here's the script. Save it in a file and chmod +x it.
The script accepst clear text only. No spaces in the filename.
Usage is:
script file.txt language_code - reads the file
en for English and so on.
or
script file.txt language_code l
encodes with lame. g encodes with gogo (faster. considerable difference if converting an unabridged book).
Code:
#!/bin/sh
# txt2mp3 - convert text files to mp3 audio files (aka audiobooks)
# v0.1
#
# (c) 2011 http://www.gnu.org/copyleft/gpl.html
#
# OBS.: install some pre-requisites first, with
# sudo apt-get install espeak lame gogo
# espeak parameters
speed=200 #160
pitch=70 #50
paragraph=40 #0
gap=0
lang=$2
if [ "$1" = "" ]; then
clear
echo "No arguments. The usage is:"
echo "$0 file.txt lang_code [g | l] "
echo "g is for gogo, l for lame encoding."
echo "Without g or l text will be played only."
echo "Gogo is more than 2 times faster than lame "
echo "and with speech encoding there are no "
echo "substantial quality differences."
echo "Language code is en, pl, ru and so on."
echo "Refer to espeak manual."
echo "Look inside the file to change speed, pitch etc."
echo "because these are kind of fixed preferences."
exit
fi
if [ "$2" = "" ]; then
echo "Not enough arguments. The usage is:"
echo "$0 file.txt lang_code [g | l]."
echo "g is for gogo, l for lame encoding."
echo "Without g or l text will be played only."
echo "Gogo is more than 2 times faster than lame "
echo "and with speech encoding there are no "
echo "substantial quality differences."
echo "Language code is en, pl, ru and so on."
echo "Refer to espeak manual."
echo "Look inside the file to change speed, pitch etc."
echo "because these are kind of fixed preferences."
exit
exit
fi
if [ "$2" = g ]; then
echo "The second argument should be the language: en, pl and so on."
echo "The optional 'g' or 'l' goes on third position."
exit
fi
# encoding
encode="$3" # If g or l in command line is ommited, the text will be played.
TXT_FILE="$1"
BASENAME=`echo "$TXT_FILE" | sed 's/\(.*\)\(\....$\)/\1/g'`
echo "Processing ${TXT_FILE} with TTS"
if [ "$encode" = l ] ; then
espeak -f "$1" -gap $gap -s $speed -l $paragraph -p $pitch -v$lang --stdout | \
lame --verbose --preset cbr 32 - "${BASENAME}_espeak-l.mp3"
echo "...done! Voice saved as ${BASENAME}_espeak-l.mp3"
elif [ "$encode" = g ] ; then
espeak -f "$1" -gap $gap -s $speed -l $paragraph -p $pitch -v$lang --stdout | \
gogo stdin -b 32 -m m -emp 5 "${BASENAME}_espeak-g.mp3"
echo "...done! Voice saved as ${BASENAME}_espeak-g.mp3"
else
espeak -f "$1" -s $speed -l $paragraph -p $pitch -v$lang
echo "...done! Add 'g' or 'l' to command line to encode. "
fi
I also cut the file afterwards into 15 minutes chunks cause my phone much better handles them that way (better scrolling, quicker search for a chapter if necessary).
I use mp3splt with -0 0.2 which makes an overlap of 2 sec. betwen chunks.
Bookmarks