Convert ebooks to audiobooks with chapters and metadata using dynamic AI models and voice cloning. Supports 1,107+ languages!
CPU/GPU Converter from eBooks to audiobooks with chapters and metadata
using XTTSv2, Bark, Vits, Fairseq, YourTTS and more. Supports voice cloning and +1110 languages!
[!IMPORTANT]
This tool is intended for use with non-DRM, legally acquired eBooks only.
The authors are not responsible for any misuse of this software or any resulting legal consequences.
Use this tool responsibly and in accordance with all applicable laws.
New Default Voice Demo
https://github.com/user-attachments/assets/750035dc-e355-46f1-9286-05c1d9e88cea
Rainy Day Voice
https://github.com/user-attachments/assets/d25034d9-c77f-43a9-8f14-0d167172b080
David Attenborough Voice
https://github.com/user-attachments/assets/0d437a41-0b0d-48ed-8c9b-02763d5e48ea
Example
Arabic (ar) | Chinese (zh) | English (en) | Spanish (es) |
---|---|---|---|
French (fr) | German (de) | Italian (it) | Portuguese (pt) |
Polish (pl) | Turkish (tr) | Russian (ru) | Dutch (nl) |
Czech (cs) | Japanese (ja) | Hindi (hi) | Bengali (bn) |
Hungarian (hu) | Korean (ko) | Vietnamese (vi) | Swedish (sv) |
Persian (fa) | Yoruba (yo) | Swahili (sw) | Indonesian (id) |
Slovak (sk) | Croatian (hr) | Tamil (ta) | Danish (da) |
[!IMPORTANT]
Before to post an install or bug issue search carefully to the opened and closed issues TAB
to be sure your issue does not exist already.
[!NOTE]
Lacking of any standards structure like what is a chapter, paragraph, preface etc.
you should first remove manually any text you don’t want to be converted in audio.
git clone https://github.com/DrewThomasson/ebook2audiobook.git
cd ebook2audiobook
./ebook2audiobook.sh # Run launch script
Mac Ebook2Audiobook Launcher.command
ebook2audiobook.cmd # Run launch script or double click on it
ebook2audiobook.cmd
python app.py --share
(all OS)./ebook2audiobook.sh --share
(Linux/MacOS)ebook2audiobook.cmd --share
(Windows)[!IMPORTANT]
If the script is stopped and run again, you need to refresh your gradio GUI interface
to let the web page reconnect to the new connection socket.
Linux/MacOS:
./ebook2audiobook.sh --headless --ebook <path_to_ebook_file> \
--voice [path_to_voice_file] --language [language_code]
Windows
ebook2audiobook.cmd --headless --ebook <path_to_ebook_file>
--voice [path_to_voice_file] --language [language_code]
[–ebook]: Path to your eBook file
[–voice]: Voice cloning file path (optional)
[–language]: Language code in ISO-639-3 (i.e.: ita for italian, eng for english, deu for german…).
Default language is eng and --language is optional for default language set in ./lib/lang.py.
The ISO-639-1 2 letters codes are also supported.
(must be a .zip file containing the mandatory model files. Example for XTTS: config.json, model.pth, vocab.json and ref.wav)
./ebook2audiobook.sh --headless --ebook <ebook_file_path> \
--voice <target_voice_file_path> --language <language> --custom_model <custom_model_path>
ebook2audiobook.cmd --headless --ebook <ebook_file_path> \
--voice <target_voice_file_path> --language <language> --custom_model <custom_model_path>
model_name.zip
file,./ebook2audiobook.sh --help
ebook2audiobook.cmd --help
```python
app.py --help
```
usage: app.py [-h] [--script_mode SCRIPT_MODE] [--session SESSION] [--share]
[--headless] [--ebook EBOOK] [--ebooks_dir EBOOKS_DIR]
[--language LANGUAGE] [--voice VOICE] [--device {cpu,gpu,mps}]
[--tts_engine {xtts,bark,vits,fairseq,yourtts}]
[--custom_model CUSTOM_MODEL] [--fine_tuned FINE_TUNED]
[--output_format OUTPUT_FORMAT] [--temperature TEMPERATURE]
[--length_penalty LENGTH_PENALTY] [--num_beams NUM_BEAMS]
[--repetition_penalty REPETITION_PENALTY] [--top_k TOP_K] [--top_p TOP_P]
[--speed SPEED] [--enable_text_splitting] [--output_dir OUTPUT_DIR]
[--version]
Convert eBooks to Audiobooks using a Text-to-Speech model. You can either launch the Gradio interface or run the script in headless mode for direct conversion.
options:
-h, --help show this help message and exit
--session SESSION Session to resume the conversion in case of interruption, crash,
or reuse of custom models and custom cloning voices.
**** The following option are for gradio/gui mode only:
Optional
--share Enable a public shareable Gradio link.
**** The following options are for --headless mode only:
--headless Run the script in headless mode
--ebook EBOOK Path to the ebook file for conversion. Cannot be used when --ebooks_dir is present.
--ebooks_dir EBOOKS_DIR
Relative or absolute path of the directory containing the files to convert.
Cannot be used when --ebook is present.
--language LANGUAGE Language of the e-book. Default language is set
in ./lib/lang.py sed as default if not present. All compatible language codes are in ./lib/lang.py
optional parameters:
--voice VOICE (Optional) Path to the voice cloning file for TTS engine.
Uses the default voice if not present.
--device {cpu,gpu,mps}
(Optional) Pprocessor unit type for the conversion.
Default is set in ./lib/conf.py if not present. Fall back to CPU if GPU not available.
--tts_engine {xtts,bark,vits,fairseq,yourtts}
(Optional) Preferred TTS engine (available are: ['xtts', 'bark', 'vits', 'fairseq', 'yourtts'].
Default depends on the selected language. The tts engine should be compatible with the chosen language
--custom_model CUSTOM_MODEL
(Optional) Path to the custom model zip file cntaining mandatory model files.
Please refer to ./lib/models.py
--fine_tuned FINE_TUNED
(Optional) Fine tuned model path. Default is builtin model.
--output_format OUTPUT_FORMAT
(Optional) Output audio format. Default is set in ./lib/conf.py
--temperature TEMPERATURE
(xtts only, optional) Temperature for the model.
Default to config.json model. Higher temperatures lead to more creative outputs.
--length_penalty LENGTH_PENALTY
(xtts only, optional) A length penalty applied to the autoregressive decoder.
Default to config.json model. Not applied to custom models.
--num_beams NUM_BEAMS
(xtts only, optional) Controls how many alternative sequences the model explores. Must be equal or greater than length penalty.
Default to config.json model.
--repetition_penalty REPETITION_PENALTY
(xtts only, optional) A penalty that prevents the autoregressive decoder from repeating itself.
Default to config.json model.
--top_k TOP_K (xtts only, optional) Top-k sampling.
Lower values mean more likely outputs and increased audio generation speed.
Default to config.json model.
--top_p TOP_P (xtts only, optional) Top-p sampling.
Lower values mean more likely outputs and increased audio generation speed. Default to 0.85
--speed SPEED (xtts only, optional) Speed factor for the speech generation.
Default to config.json model.
--enable_text_splitting
(xtts only, optional) Enable TTS text splitting. This option is known to not be very efficient.
Default to config.json model.
--output_dir OUTPUT_DIR
(Optional) Path to the output directory. Default is set in ./lib/conf.py
--version Show the version of the script and exit
Example usage:
Windows:
Gradio/GUI:
ebook2audiobook.cmd
Headless mode:
ebook2audiobook.cmd --headless --ebook '/path/to/file'
Linux/Mac:
Gradio/GUI:
./ebook2audiobook.sh
Headless mode:
./ebook2audiobook.sh --headless --ebook '/path/to/file'
NOTE: in gradio/gui mode, to cancel a running conversion, just click on the [X] from the ebook upload component.
Available tags: latest
(CUDA 11), cpu
, rocm
, cuda11
, cuda12
, cuda128
, xpu
(x86 only)
To run the Docker container and start the Gradio interface, use the following command:
-Run with CPU only
docker run --pull always --rm -p 7860:7860 athomasson2/ebook2audiobook
-Run with GPU Speedup (NVIDIA compatible only)
docker run --pull always --rm --gpus all -p 7860:7860 athomasson2/ebook2audiobook
docker build -t athomasson2/ebook2audiobook .
This command will start the Gradio interface on port 7860.(localhost:7860)
--help
All ebook2audiobooks will have the base dir of /app/
For example:
tmp
= /app/tmp
audiobooks
= /app/audiobooks
mkdir input-folder && mkdir Audiobooks
docker run --pull always --rm \
-v $(pwd)/input-folder:/app/input_folder \
-v $(pwd)/audiobooks:/app/audiobooks \
athomasson2/ebook2audiobook \
--headless --ebook /input_folder/YOUR_EBOOK_FILE
docker run --pull always --rm athomasson2/ebook2audiobook --help
That will output this
Help command output
This project uses Docker Compose to run locally. You can enable or disable GPU support
by setting either *gpu-enabled
or *gpu-disabled
in docker-compose.yml
git clone https://github.com/DrewThomasson/ebook2audiobook.git
cd ebook2audiobook
docker-compose.yml
and change *gpu-disabled
to *gpu-enabled
docker-compose up -d
python: can't open file '/home/user/app/app.py': [Errno 2] No such file or directory
(Just remove all post arguments as I replaced the CMD
with ENTRYPOINT
in the Dockerfile)
docker run --pull always athomasson2/ebook2audiobook app.py --script_mode full_docker
- > corrected - > docker run --pull always athomasson2/ebook2audiobook
docker run --pull always athomasson2/ebook2audiobook --share
Docker gets stuck downloading Fine-Tuned models.
(This does not happen for every computer but some appear to run into this issue)
Disabling the progress bar appears to fix the issue,
as discussed here in #191
Example of adding this fix in the docker run
command
docker run --pull always --rm --gpus all -e HF_HUB_DISABLE_PROGRESS_BARS=1 -e HF_HUB_ENABLE_HF_TRANSFER=0 \
-p 7860:7860 athomasson2/ebook2audiobook
For an XTTS custom model a ref audio clip of the voice reference is mandatory:
.epub
, .pdf
, .mobi
, .txt
, .html
, .rtf
, .chm
, .lit
,.pdb
, .fb2
, .odt
, .cbr
, .cbz
, .prc
, .lrf
, .pml
,.snb
, .cbc
, .rb
, .tcr
.epub
or .mobi
for automatic chapter detection['m4b', 'm4a', 'mp4', 'webm', 'mov', 'mp3', 'flac', 'wav', 'ogg', 'aac']
(set in ./lib/conf.py) file with metadata and chapters.--help
parameter at the end of the docker run command for more information.