Skip to content

Instantly share code, notes, and snippets.

@p0n1
Last active April 29, 2024 13:53
Show Gist options
  • Save p0n1/cba98859cdb6331cc1aab835d62e4fba to your computer and use it in GitHub Desktop.
Save p0n1/cba98859cdb6331cc1aab835d62e4fba to your computer and use it in GitHub Desktop.
This tutorial was crafted with the help of ChatGPT. Leave a comment if you find any mistakes.

EPUB to Audiobook Converter for Windows Users

Welcome to the tutorial on using the EPUB to Audiobook Converter tool on Windows. If you're not familiar with command-line tools or programming, don't worry. This guide is specially designed for users like you. Let's get started!

This tutorial may be out of date. So also check the README of https://github.com/p0n1/epub_to_audiobook for latest command options.

1. Pre-requisites:

  • A working internet connection
  • An active Microsoft Azure account with access to the Microsoft Cognitive Services Speech Services. If you don't have one, follow this link to create it.
  • Download and install Git for Windows

2. Environment Variables

Option A: Setting Environment Variables via GUI

  1. Right-click on This PC or Computer from your desktop or File Explorer, then click on Properties.
  2. On the left side, click on Advanced system settings.
  3. Under the Advanced tab, click on Environment Variables....
  4. In the User Variables section, click on New....
  5. For Variable name, enter MS_TTS_KEY and for Variable value, enter your Azure Text-to-Speech subscription key. Click OK.
  6. Click on New... again.
  7. This time, for Variable name, enter MS_TTS_REGION and for Variable value, enter your Azure Text-to-Speech region (e.g., "westus"). Click OK.

Option B: Setting Environment Variables via Command Prompt

  1. Press Win + R, type cmd, and press Enter.
  2. Type the following commands, replacing <your_subscription_key> and <your_region> with your respective Azure details:
setx MS_TTS_KEY "<your_subscription_key>" /M
setx MS_TTS_REGION "<your_region>" /M

3. Installation:

Option A: Python Version

  1. Download and install Python. Make sure to check the box Add Python to PATH during installation.
  2. Open Git Bash (search in the start menu).
  3. Clone the repository:
git clone https://github.com/p0n1/epub_to_audiobook.git
cd epub_to_audiobook
  1. Create a virtual environment and activate it:
python -m venv venv
source venv/Scripts/activate
  1. Install the required dependencies:
pip install -r requirements.txt

Option B: Docker Version

  1. Download and install Docker for Windows.
  2. Open Command Prompt as Administrator.
  3. Pull the Docker image:
docker pull ghcr.io/p0n1/epub_to_audiobook:latest

4. Usage:

Option A: Python Version

  1. Open Git Bash.
  2. Navigate to the project directory:
cd path/to/epub_to_audiobook

Replace path/to/ with the actual path where you cloned the repository.

  1. Convert the EPUB to Audiobook:
python main.py <input_file> <output_folder> [--voice_name <voice_name>] [--language <language>]

Example:

python main.py examples/The_Life_and_Adventures_of_Robinson_Crusoe.epub output_folder

Option B: Docker Version

  1. Open Command Prompt as Administrator.
  2. Navigate to the directory where your EPUB file is located.
  3. Run the tool:
docker run -i -t --rm -v %cd%:/app -e MS_TTS_KEY=%MS_TTS_KEY% -e MS_TTS_REGION=%MS_TTS_REGION% ghcr.io/p0n1/epub_to_audiobook your_book.epub audiobook_output

Replace your_book.epub with the name of your EPUB file.

5. Further Information:

That's it! You've now successfully converted your EPUB into an audiobook. Enjoy listening!

@athriren
Copy link

I had just forgotten to activate the virtual environment again, embarrassing. I have it working via Python on Windows now as well. Thank you very much for this tool and for the step-by-step instructions.

@hahahabote
Copy link

I'm getting an error as below when I try to run in Python
ModuleNotFoundError: No module named 'ebooklib'

This is the full window
python3 epub_to_audiobook.py C:/Users/Brett/Documents/Epub/HarryPotter1.epub C:/Users/Brett/Documents/EpubOutput
Traceback (most recent call last):
File "C:\Users\Brett\epub_to_audiobook\epub_to_audiobook.py", line 102, in
main()
File "C:\Users\Brett\epub_to_audiobook\epub_to_audiobook.py", line 98, in main
AudiobookGenerator(config).run()
File "C:\Users\Brett\epub_to_audiobook\audiobook_generator\core\audiobook_generator.py", line 37, in run
book_parser = get_book_parser(self.config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Brett\epub_to_audiobook\audiobook_generator\book_parsers\base_book_parser.py", line 41, in get_book_parser
from audiobook_generator.book_parsers.epub_book_parser import EpubBookParser
File "C:\Users\Brett\epub_to_audiobook\audiobook_generator\book_parsers\epub_book_parser.py", line 5, in
import ebooklib
ModuleNotFoundError: No module named 'ebooklib'
(venv)

@p0n1
Copy link
Author

p0n1 commented Dec 7, 2023

Hi @hahahabote. Did you follow this step called 'Create a virtual environment and activate it' in the above guide? And your issue looks similar to this one https://gist.github.com/p0n1/cba98859cdb6331cc1aab835d62e4fba?permalink_comment_id=4767283#gistcomment-4767283. Besides, the epub_to_audiobook.py was renamed into main.py in a recent refactoring p0n1/epub_to_audiobook#27 (comment). You should use python3 main.py instead. Please feel free to leave a message if you have any questions.

@elizabethlundberg
Copy link

elizabethlundberg commented Jan 24, 2024

Hi @hahahabote. Did you follow this step called 'Create a virtual environment and activate it' in the above guide? And your issue looks similar to this one https://gist.github.com/p0n1/cba98859cdb6331cc1aab835d62e4fba?permalink_comment_id=4767283#gistcomment-4767283. Besides, the epub_to_audiobook.py was renamed into main.py in a recent refactoring p0n1/epub_to_audiobook#27 (comment). You should use python3 main.py instead. Please feel free to leave a message if you have any questions.

I activated the virtual environment and ran the command, and still got the same error: "No module named 'ebooklib'."

Also, when I run pip install -r requirements.txt, I get this error:
ERROR: Failed building wheel for multidict Failed to build multidict ERROR: Could not build wheels for multidict, which is required to install pyproject.toml-based projects

I can't get the Docker instructions to work, either. I'm trying to use the OpenAI engine, and the commands on the main page are giving me errors.

Sorry to be so much trouble, this would be a huge huge helper if I can get it to work. Thanks!

EDIT: Got it to work by installing C++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment