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

# 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”

      say -f “${f%.mobi}.txt” -o “${f%.mobi}.aiff” 

done

  for f in `ls *.aiff`

    do

      echo “Using filename: ” ${f}

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

       rm -f ${f}

done

# restore default separator definitions

IFS=$oIFS

~/convert-audiobook-to-mp3-mac.sh *.prc

~/convert-audiobook-to-mp3-mac.sh *.mobi

~/convert-audiobook-to-mp3-mac.sh *.pdf

~/convert-audiobook-to-mp3-mac.sh:

#!/bin/bash

  for file in `ls “$1″`

    do

      echo “Using filename: ” “$1”

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

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

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

done

  for f in `ls “$1.aiff”`

    do

      echo “Using filename: ” “$1.aiff”

       lame -V2 “$1.aiff” “$1.mp3”

       rm -f “$1.aiff”

done

# restore default separator definitions

IFS=$oIFS

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