This project is a Python script to convert the chapters of an EPUB book into audio files using edge-tts Text-to-Speech (TTS) technology. The script supports concurrency, custom voices, and can clean the text before synthesizing it into speech.
- Converts chapters from an EPUB file to MP3 audio files.
- Choose from a variety of voices (default is "en-US-EricNeural").
- Supports retry attempts for the TTS API.
- Allows skipping chapters and paragraphs.
- Option to clean the text by removing specified strings.
- Save the text to a JSON file instead of generating audio (dry-run mode).
- Merge generated audio files into a single audio file per chapter.
edge-tts
(Text-to-Speech API by Microsoft Cognitive Services)
-
Clone the repository:
git clone https://github.com/mustafaIhssan/edge-tts-epub cd edge-tts-epub
-
Install the required Python packages:
pip install -r requirements.txt
-
Ensure that you have the
ffmpeg
library installed, which is required bypydub
:- On Ubuntu:
sudo apt-get install ffmpeg
- On MacOS:
brew install ffmpeg
- On Windows, download the FFmpeg executable from here and follow the installation instructions.
- On Ubuntu:
python main.py --output-dir OUTPUT_DIR --path EPUB_PATH [options]
--output-dir
: Output directory for audio files (default:./audiobook/
)--path
: Path to the EPUB file (default:./book.epub
)--voice
: Voice to use in Text-to-Speech (default:en-US-EricNeural
) Voices List--retry-attempts
: Number of times to retry on failure (default: 10)--max-concurrent-tasks
: Limit the number of concurrent tasks (default: 5)--dry-run
: Save the text to be spoken as a JSON file instead of actually speaking it--skip-chapters
: Number of chapters to skip (default: 0)--skip-paragraphs
: Number of paragraphs to skip (default: 0)--start-chapter
: Chapter number to start from (default: 0)--end-chapter
: Chapter number to end at (default: 0)--clean-text
: Clean the text before generating audio (default: True)--remove-text-list
: List of text strings to remove
Convert chapters from an EPUB file and save the audio files:
python main.py --output-dir ./output/ --path ./book.epub --voice en-US-EricNeural
Dry run mode (save chapters as JSON file instead of generating audio):
python main.py --output-dir ./output/ --path ./book.epub --dry-run
Feel free to submit issues, fork the repository, and send pull requests with updates. Any contributions are highly appreciated!
This project is licensed under the MIT License. See the LICENSE file for details.
If you encounter any problems or have any questions, feel free to open an issue or reach out to me directly. Happy audiobook making!