Skip to content

Instantly share code, notes, and snippets.

@p0n1
Last active April 29, 2024 13:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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!

@delinter
Copy link

Thank you for this. I probably would have figured it out on my own, but I truly appreciate the thorough documentation.

Knowing is half the battle.

@athriren
Copy link

athriren commented Nov 20, 2023

I have this working on my Macbook but have a much more powerful Windows machine I am trying to use for this purpose. I am a total novice at this kind of stuff on Windows, but I have followed the instructions to the best of my ability and I am still stuck.

  • When I use command prompt to run docker pull ghcr.io/p0n1/epub_to_audiobook:latest i get a return that says
request returned Internal Server Error for API route and version 
http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/create?fromImage=ghcr.io%2Fp0n1%2Fepub_to_audiobook&tag=latest, 
check if the server supports the requested API version

I tried opening Docker Desktop and manually searching for the image but there are no results for p0n1 or epub_to_audiobook.

  • When I used the Python instructions instead, everything works through the creation of the venv and installation of the dependencies. However, when I navigate to the project directory in Git Bash and run something, for example python3 epub_to_audiobook.py -h, I get an error that states
Traceback (most recent call last):
  File "C:\epub_to_audiobook\epub_to_audiobook.py", line 6, in <module>
    import ebooklib
ModuleNotFoundError: No module named 'ebooklib'

This is confusing to me because within the C:\epub_to_audiobook\venv\Lib\site-packages folder there exists a folder named ebooklib with the associated .py files.

Any help would be much appreciated!

@p0n1
Copy link
Author

p0n1 commented Nov 21, 2023

Hi @athriren.

For docker on windows, I'm sorry since I also have little knowledge about this. I found others are also discussing about this over here docker/for-win#13693. I guess you could try to rest docker settings, upgrade/downgrade docker versions, reboot or reinstall. You cannot find the image in Docker Desktop because it's hosted on ghcr.io not docker hub.

For Python on windows, remember you need to run source venv/Scripts/activate in path/to/epub_to_audiobook each time after you reopen the command prompt or Git Bash to make sure correct python environment is loaded. After activating the virtual environment, ensure that the Python interpreter you're using is the one from the virtual environment. Run where python to see the path of the Python interpreter that is being used. You could also use pip list to check the packages installed. Besides, I think you could try replace python3 with python in your command.

Feel free to leave a message if you still encounter any issues.

@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