PDA

View Full Version : [SOLVED] Batch Text to Speak With Espeak please.



sTpny
June 6th, 2011, 05:59 PM
Hi Everyone,

I use my mp3 player to listen to audio-books and I'd like to know how to make my own from ebooks using espeak. So..

I have chopped an ebook (Mary Crofts "How I clobbered every cash confiscatory agency known to man, the 1000 Papercuts Technique") into Parts and Chapters and saved them all individually as separate files, ex:

Papercuts - Part 1 - 1 - What Happened
Papercuts - Part 1 - 2 - How it happened

etc..

Now I would like to use the magic of espeak to convert the files into usable audio for my mp3 player, but I would also like to use the magic of bash scripting to convert all of them at the same time. My Bash Magic is still very limited though, so I have no clue how to do this.

Could someone please help formulate a command line that will batch convert my ebook files into mp3's, so I can keep learning new things as a I walk my little weiner dog. This will be very much appreciated.

Thanks.

epicoder
June 6th, 2011, 06:12 PM
Run this command in bash (It won't work in dash) in the same directory as your text files:

for file in "./Papercuts - Part*.txt"; do espeak [your options here] -f "$file" --stdout | lame [your options here] - $(basename "$file" .txt)".mp3"; doneThis code is untested (as I am running windows atm) so please point out any mistakes I may have made.

sTpny
June 7th, 2011, 05:35 AM
Run this command in bash (It won't work in dash) in the same directory as your text files:

for file in "./Papercuts - Part*.txt"; do espeak [your options here] -f "$file" --stdout | lame [your options here] - $(basename "$file" .txt)".mp3"; doneThis code is untested (as I am running windows atm) so please point out any mistakes I may have made.


Thanks.. I should be able to make something work with that.. I'll try it out in the AM.

geirha
June 7th, 2011, 07:09 AM
The * needs to be outside the quotes, otherwise it won't have the special wildcard meaning.



for f in "Papercuts - Part"*.txt; do
espeak -f "$f" --stdout | lame - "${f%.txt}.mp3"
done

sTpny
June 8th, 2011, 06:31 AM
The * needs to be outside the quotes, otherwise it won't have the special wildcard meaning.



for f in "Papercuts - Part"*.txt; do
espeak -f "$f" --stdout | lame - "${f%.txt}.mp3"
done



That worked.. thanks. :)

epicoder
June 8th, 2011, 02:40 PM
Actually, * does work in double quotes.

# for x in "./desk*.png"
> do echo $x
> done
./desktop.png ./desktop2.png
geirha was most likely thinking of single quotes ' , in which everything loses it's special meaning (except ' ).

geirha
June 8th, 2011, 07:09 PM
Actually, * does work in double quotes.

# for x in "./desk*.png"
> do echo $x
> done
./desktop.png ./desktop2.png
geirha was most likely thinking of single quotes ' , in which everything loses it's special meaning (except ' ).

Nope. The for-loop there only iterates once, on the single word "./desk*.png". The pattern is expanded on the echo command, since you failed to quote $x properly.



$ touch file1.txt file2.txt
$ for f in "./file*.txt"; do echo "$f"; done
./file*.txt
$ for f in ./file*.txt; do echo "$f"; done
./file1.txt
./file2.txt