Skip to content

Instantly share code, notes, and snippets.

@p0n1
Last active July 9, 2025 15:22
Show Gist options
  • Select an option

  • Save p0n1/cba98859cdb6331cc1aab835d62e4fba to your computer and use it in GitHub Desktop.

Select an option

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!

@neetalshah
Copy link

I activated the virtual environment and run the command and still getting following error"

eltor@DESKTOP-OC3752P MINGW64 ~/epub_to_audiobook (main)
$ python main.py --tts edge text/Empire_of_Storms.epub xx/  --log INFO
C:\Users\eltor\epub_to_audiobook\venv\Lib\site-packages\ebooklib\epub.py:1423: FutureWarning: This search incorrectly ignores the root element, and will be fixed in a future version.  If you rely on the current behaviour, change it to './/xmlns:rootfile[@media-type]'
  for root_file in tree.findall('//xmlns:rootfile[@media-type]', namespaces={'xmlns': NAMESPACES['CONTAINERNS']}):
C:\Users\eltor\epub_to_audiobook\venv\Lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
2024-08-20 18:34:24 [INFO] Chapters count: 84.
2024-08-20 18:34:24 [INFO] Converting chapters from 1 to 84.
2024-08-20 18:34:24 [INFO] \u2728 Total characters in selected book: 1090685 \u2728
Estimate book voiceover would cost you roughly: $0.00

Do you want to continue? (y/n)
y
2024-08-20 18:34:26 [INFO] Converting chapter 1/84: For_Tamarmy_champion_fairy_godmother_and_knight_in_shinin, characters: 121
C:\Users\eltor\epub_to_audiobook\venv\Lib\site-packages\pydub\utils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
  warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
2024-08-20 18:34:26 [WARNING] Failed to decode the chunk, reason: [WinError 2] The system cannot find the file specified, returning a silent chunk.
Traceback (most recent call last):
  File "C:\Users\eltor\epub_to_audiobook\main.py", line 147, in <module>
    main()
  File "C:\Users\eltor\epub_to_audiobook\main.py", line 143, in main
    AudiobookGenerator(config).run()
  File "C:\Users\eltor\epub_to_audiobook\audiobook_generator\core\audiobook_generator.py", line 101, in run
    tts_provider.text_to_speech(
  File "C:\Users\eltor\epub_to_audiobook\audiobook_generator\tts_providers\edge_tts_provider.py", line 170, in text_to_speech
    asyncio.run(communicate.save(output_file))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\eltor\epub_to_audiobook\audiobook_generator\tts_providers\edge_tts_provider.py", line 121, in save
    audio.export(audio_fname)
  File "C:\Users\eltor\epub_to_audiobook\venv\Lib\site-packages\pydub\audio_segment.py", line 963, in export
    p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
(venv)

No matter what I do it. Unable to work on RaspberryPi also.

Any help would be appreciated.

@p0n1
Copy link
Author

p0n1 commented Sep 5, 2024

Hi @neetalshah. I see warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning). Could you try install ffmpeg first? Check this https://github.com/p0n1/epub_to_audiobook?tab=readme-ov-file#filenotfounderror-errno-2-no-such-file-or-directory-ffmpeg. On Windows, you may need to download the ffmpeg binary and add it to the system PATH.

@camillesoriano
Copy link

hello, sorry i'm new to this, is there any way to do the voices with microsoft edge tts? It works great in tts azure but it seems like I have to pay?
thank you so much!

image

@camillesoriano
Copy link

hello, sorry i'm new to this, is there any way to do the voices with microsoft edge tts? It works great in tts azure but it seems like I have to pay? thank you so much!

image

I managed to do it by adding --tts edge
image
after running it, it says:
image
which is exactly what I wanted! leaving it here in case it can be of help for someone.

kudos! thanks again for creating this awesome tool. I can finally cancel my audible subscription lol

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