Bulk convert mobi ebooks to audiobooks (robotic)

It works, the quality, well, not so much. Works good on the mac, Linux is still spotty.

Install calibre:

apt-get update

apt install calibre

# Convert the mobi to txt files

for file in *.mobi; do ebook-convert “$file” “${file%.mobi}.txt” ; done

# Convert txt to audio

apt-get install espeak lame ruby

wget https://gist.githubusercontent.com/sentientwaffle/2186807/raw/69d7f4e974b9e553ee7fd7de1ac3a9bee3095cce/speak.rb

# Works if no spaces in names

for file in *.txt; do ruby speak.rb  “$file”  ; done 

for file in *.txt; do espeak -v en-us -f ${file} -s 130 -w “${file%.txt}.wav” –split=30  ; done

eSpeak will take a few minutes to convert your content, just sit tight, it will peg one CPU, it is not multithreaded.

Quality is still not great.

Ok, so wrap it up in one nice script, this works 100% but the voices in espeak are crap:

#!/bin/bash

# Save default separator definitions

oIFS=$IFS

# define new line as a separator, filenames can have spaces

IFS=$’\n’;

# For each file (f) listed as duplicated by fdupes, recursively

  for f in `ls *.mobi`

    do

      echo “Using filename: ” ${f}

      ebook-convert “$f” “${f%.mobi}.txt”

      espeak -v en-us -f “${f%.mobi}.txt” -s 130 -w “${f%.mobi}.wav” –split=30

done

  for f in `ls *.wav`

    do

      echo “Using filename: ” ${f}

       lame -V2 ${f} ${f%.wav}.mp3

       rm -f ${f}

done

# restore default separator definitions

IFS=$oIFS

Can do this on a mac using the built in Alex voice:

brew install caskroom/cask/calibre

brew install lame

brew install mp3splt

convert-ebook-to-audiobook-mp3-mac.sh

#!/bin/bash

# brew install caskroom/cask/calibre

# brew install lame

# brew install mp3splt

echo “Using filename: ” “${1%.mobi}”

# Convert ebook to text

ebook-convert “$1” “${1%.mobi}”.txt –enable-heuristics –html-unwrap-factor 0.1

# Edit out any weirdness

# Will probably need to have a list of standard/recurring screwups to replace too like dr. etc.

vi “${1%.mobi}”.txt

# Convert txt to speech

# Available Apple voices (US English): Alex Fred Samantha Victoria

# say -r 180 –voice Alex -f “${1%.mobi}”.txt -o “${1%.mobi}”.aiff

# say -r 180 –voice Fred -f “${1%.mobi}”.txt -o “${1%.mobi}”.aiff

say -r 180 –voice Samantha -f “${1%.mobi}”.txt -o “${1%.mobi}”.aiff

# say -r 180 –voice Victoria -f “${1%.mobi}”.txt -o “${1%.mobi}”.aiff

# Convert aiff to mp3

lame -V2 “${1%.mobi}”.aiff “${1%.mobi}”.mp3

# Clean up the aiff giant file

rm -f “${1%.mobi}”.aiff

# Split the giant mp3 into smaller pieces and dump into a directory

mp3splt -a -t 15.1 -o “${1%.mobi}”-@n -d “${1%.mobi}” “${1%.mobi}”.mp3

Splitting big mp3’s into smaller pieces:

mp3splt -a -t 15.1 -o Saint\ Death\ -\ Mark\ Dawson-@n -d Saint\ Death\ -\ Mark\ Dawson Saint\ Death\ -\ Mark\ Dawson.mp3

mp3splt -a -t 5.10 -o Lesson_01-@n -d Lesson_01 Lesson_01.mp3

The -a tells mp3splt to auto-adjust the split point with silence detection.

The -t 5.10 tells it to make the files 5 minutes and 10 seconds long since the file is a little over 30 minutes long. (This length may vary a bit due to the -a option).

The -o Lesson_01-@n tells it to name the files as Lesson_01 followed by a track number.

The -d Lesson_01 tells it to put the files in a directory called Lesson_01.

last is input file.mp3

So: mp3splt -a -t 5.10 -o outputfilename-@n -d OutputDirectory InputFilename.mp3