/epub2tts

Turn an epub or text file into an audiobook

Primary LanguagePythonApache License 2.0Apache-2.0

This script takes an epub (or text file) and reads it to an mp3 or an m4b audiobook file, using TTS by https://github.com/coqui-ai/TTS

I recognize this is not very user friendly, but I wanted to share in case folks thought it was useful. If there are a few more people than myself that find this is useful I will keep working on turning it into something that could be used by someone without dev experience.

NOTE: Now with OpenAI TTS support! It's not free, but the average cost for a few books I tested was around $7. If you use --openai <API key> flag epub2tts will provide a cost estimate and prompt you to approve before continuing.

NOTE: HUGE thanks to a recent PR from wonka929, epub2tts now recognizes when a CUDA GPU is available and will use it automatically. In a brief test I did, the speedup was incredible!

USAGE:

Usage:

EPUB: epub2tts my-book.epub

TEXT: epub2tts my-book.txt

URL: epub2tts --url https://www.example.com/page --name example-page

To use OpenAI TTS, add: --openai <your API key> (Use speaker option to specify voice other than onyx: --speaker shimmer)

To change speaker (ex p307 for a good male voice), add: --speaker p307

To output in mp3 format instead of m4b, add: --mp3

To skip reading any links, add: --skip-links

Using --scan will list excerpts of each chapter, then exit. This is helpful for finding which chapter to start and end on if you want to skip bibliography, TOC, etc.

To specify which chapter to start on (ex 3): --start 3

To specify which chapter to end on (ex 20): --end 20

To specify bitrate (ex 30k): --bitrate 30k

If epub2tts is interrupted or crashes, you can run it again with the same parameters and it will pick up where it left off, assuming it made it far enough to save some WAV files. If you want to start fresh, be sure to delete any of the wav files (with the same name as the epub) in the working directory before running again.

DOCKER INSTRUCTIONS:

Voice models will be saved locally in ~/.local/share/tts

For Linux and MacOS:

alias epub2tts='docker run -v "$PWD:$PWD" -v ~/.local/share/tts:/root/.local/share/tts -w "$PWD" ghcr.io/aedocw/epub2tts:release'

For Windows: Pre-requisites:

  • Install Docker Desktop
  • From PowerShell run "mkdir ~/.local/share/tts"
#Example for running scan of "mybook.epub"
docker run -v ${PWD}/.local/share/tts:/root/.local/share/tts -v ${PWD}:/root -w /root ghcr.io/aedocw/epub2tts:release mybook.epub --scan

#Example for reading parts 3 through 15 of "mybook.epub"
docker run -v ${PWD}/.local/share/tts:/root/.local/share/tts -v ${PWD}:/root -w /root ghcr.io/aedocw/epub2tts:release mybook.epub --start 3 --end 15

MAC INSTALLATION:

This installation requires Python < 3.12 and Homebrew (I use homebrew to install espeak, pyenv and ffmpeg). Per this bug, mecab should also be installed via homebrew.

Voice models will be saved locally in ~/.local/share/tts

#install dependencies
brew install espeak pyenv ffmpeg mecab
#install epub2tts
git clone https://github.com/aedocw/epub2tts
cd epub2tts
pyenv install 3.11
pyenv local 3.11
#OPTIONAL - install this in a virtual environment
python -m venv .venv && source .venv/bin/activate
pip install .

LINUX INSTALLATION:

These instructions are for Ubuntu, but should work (with appropriate package installer mods) for just about any repo. Ensure you have ffmpeg installed before use.

Voice models will be saved locally in ~/.local/share/tts

#install dependencies
sudo apt install espeak-ng ffmpeg
#clone the repo
git clone https://github.com/aedocw/epub2tts
cd epub2tts
pip install .

DEVELOPMENT INSTALL:

#clone the repo
git clone https://github.com/aedocw/epub2tts
cd epub2tts
#create a virtual environment
python -m venv .venv
#activate the virtual environment
source .venv/bin/activate
#install dependencies
sudo apt install espeak-ng ffmpeg
pip install -r requirements.txt