DrewThomasson / ebook2audiobookXTTS

Generates an audiobook with chapters and ebook metadata using Calibre and Xtts from Coqui tts, and with optional voice cloning, and supports multiple languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ“š ebook2audiobook

Convert eBooks to audiobooks with chapters and metadata using Calibre and Coqui XTTS. Supports optional voice cloning and multiple languages!

🌟 Features

  • πŸ“– Converts eBooks to text format with Calibre.
  • πŸ“š Splits eBook into chapters for organized audio.
  • πŸŽ™οΈ High-quality text-to-speech with Coqui XTTS.
  • πŸ—£οΈ Optional voice cloning with your own voice file.
  • 🌍 Supports multiple languages (English by default).
  • πŸ–₯️ Designed to run on 4GB RAM.

πŸ› οΈ Requirements

  • Python 3.x
  • coqui-tts Python package
  • Calibre (for eBook conversion)
  • FFmpeg (for audiobook creation)
  • Optional: Custom voice file for voice cloning

πŸ”§ Installation Instructions

  1. Install Python 3.x from Python.org.

  2. Install Calibre:

    • Ubuntu: sudo apt-get install -y calibre
    • macOS: brew install calibre
    • Windows (Admin Powershell): choco install calibre
  3. Install FFmpeg:

    • Ubuntu: sudo apt-get install -y ffmpeg
    • macOS: brew install ffmpeg
    • Windows (Admin Powershell): choco install ffmpeg
  4. Optional: Install Mecab (for non-Latin languages):

    • Ubuntu: sudo apt-get install -y mecab libmecab-dev mecab-ipadic-utf8
    • macOS: brew install mecab, brew install mecab-ipadic
    • Windows (Admin Powershell): choco install mecab (Note: Japanese support is limited)
  5. Install Python packages:

    pip install tts==0.21.3 pydub nltk beautifulsoup4 ebooklib tqdm

    For non-Latin languages:

    python -m unidic download
    pip install mecab mecab-python3 unidic

🌐 Supported Languages

  • English (en)
  • Spanish (es)
  • French (fr)
  • German (de)
  • Italian (it)
  • Portuguese (pt)
  • Polish (pl)
  • Turkish (tr)
  • Russian (ru)
  • Dutch (nl)
  • Czech (cs)
  • Arabic (ar)
  • Chinese (zh-cn)
  • Japanese (ja)
  • Hungarian (hu)
  • Korean (ko)

Specify the language code when running the script.

πŸš€ Usage

πŸ–₯️ Gradio Web Interface

  1. Run the Script:

    python custom_model_ebook2audiobookXTTS_gradio.py
  2. Open the Web App: Click the URL provided in the terminal to access the web app and convert eBooks.

πŸ“ Basic Usage

python ebook2audiobook.py <path_to_ebook_file> [path_to_voice_file] [language_code]
  • <path_to_ebook_file>: Path to your eBook file.
  • [path_to_voice_file]: Optional for voice cloning.
  • [language_code]: Optional to specify language.

🧩 Custom XTTS Model

python custom_model_ebook2audiobookXTTS.py <ebook_file_path> <target_voice_file_path> <language> <custom_model_path> <custom_config_path> <custom_vocab_path>
  • <ebook_file_path>: Path to your eBook file.
  • <target_voice_file_path>: Optional for voice cloning.
  • : Optional to specify language.
  • <custom_model_path>: Path to model.pth.
  • <custom_config_path>: Path to config.json.
  • <custom_vocab_path>: Path to vocab.json.

🐳 Using Docker

You can also use Docker to run the eBook to Audiobook converter. This method ensures consistency across different environments and simplifies setup.

πŸš€ Running the Docker Container

To run the Docker container and start the Gradio interface, use the following command:

-Run with CPU only

docker run -it --rm -p 7860:7860 athomasson2/ebook2audiobookxtts:latest

-Run with GPU Speedup (Nvida graphics cards only)

docker run -it --rm --gpus all -p 7860:7860 athomasson2/ebook2audiobookxtts:latest

This command will start the Gradio interface on port 7860.(localhost:7860)

πŸ–₯️ Docker GUI

Screenshot 2024-08-25 at 10 08 40β€―AM Screenshot 2024-08-25 at 10 08 51β€―AM

πŸ› οΈ For Custom Xtts Models

Models built to be better at a specific voice. Check out my Hugging Face page here.

To use a custom model, paste the link of the Finished_model_files.zip file like this:

David Attenborough fine tuned Finished_model_files.zip

More details can be found at the Dockerfile Hub Page.

🌐 Fine Tuned Xtts models

To find already fine-tuned XTTS models, visit this Hugging Face link 🌐. Search for models that include "xtts fine tune" in their names.

πŸŽ₯ Demos

Magic.Tree.House.45.Osborne.Mary.Pope.-.A.Crazy.Day.With.Cobras.mp4
  • Huggingface space is running on free cpu tier so expect very slow or timeout lol, just don't give it giant files is all
  • Best to duplicate space or run locally.

πŸ“š Supported eBook Formats

  • .epub, .pdf, .mobi, .txt, .html, .rtf, .chm, .lit, .pdb, .fb2, .odt, .cbr, .cbz, .prc, .lrf, .pml, .snb, .cbc, .rb, .tcr
  • Best results: .epub or .mobi for automatic chapter detection

πŸ“‚ Output

  • Creates an .m4b file with metadata and chapters.
  • Example Output: Example

πŸ™ Special Thanks

About

Generates an audiobook with chapters and ebook metadata using Calibre and Xtts from Coqui tts, and with optional voice cloning, and supports multiple languages

License:MIT License


Languages

Language:Python 97.7%Language:Dockerfile 2.3%