Transform your PDFs into engaging audiobooks with the power of OCR, LLMs, and TTS in 16 languages.
๐ Welcome to NarratorX! ๐ For the longest time, I found myself saying, "Ah shucks, there's no audiobook for this oneโฆ guess I'll have to wait or squeeze in some reading when I have free time." If youโre like me and love listening to audiobooks while doing chores ๐งน, commuting ๐ถ, or just relaxing ๐, then I guess this tool was made for you!
๐ With NarratorX, you can freely convert the PDF of that book thatโs been lingering on your to-read list into a beautifully narrated, non-robotic audiobook. Say hello to NarratorX โ savior of the busy and the lazy! By harnessing advanced OCR ๐, powerful LLMs ๐ค, and state-of-the-art TTS ๐๏ธ, NarratorX transforms your PDFs into immersive audiobooks, ready to accompany you wherever you go. And all for free, my favorite kinda payment method...
NarratorX is a passion project, specially crafted for my book club ๐๐ฌ. With support for 16 languages ๐, itโs perfect for readers worldwide. I hope it brings you joy too! So go on, read away and listen away! ๐งโจ
๐ Feature | โจ Description |
---|---|
Seamless PDF to Audiobook Conversion ๐ง | Effortlessly convert your PDFs into high-quality audiobooks using OCR ๐, LLMs ๐ค, and TTS ๐๏ธ, fully automating the process from text extraction to speech generation. |
Multi-Language Support ๐ | Supports 16 languages, including English, Spanish, French, German, Turkish, and more, making NarratorX accessible to a global audience. |
Open-Source LLM Integration ๐ | Leverage the Ollama library for local, open-source LLMs. OpenAI is optional, offering flexibility for users with different needs. |
User-Friendly Interfaces ๐ฅ๏ธ | Use either the command-line interface for quick, scriptable conversions or the Streamlit web app for a visual, interactive experience. |
Customizable Settings ๐๏ธ | Fine-tune your experience by adjusting chunk sizes, selecting models, and choosing language preferences to suit each document. |
Robust Error Handling and Logging ๐ ๏ธ | With comprehensive error handling and logging, NarratorX ensures smooth operation and easy troubleshooting if issues arise. |
demo.mp4
๐ง Sample Audiobook Conversions Here are some sample audiobook conversions created with NarratorX! (Not cherry-picked โ just pure NarratorX magic โจ)
๐ Language | ๐ Book Title | ๐ Sample Audio |
---|---|---|
๐บ๐ธ English | "The Little Prince" by Antoine de Saint-Exupรฉry | Listen ๐ถ |
๐ช๐ธ Spanish | "Don Quijote" by Miguel de Cervantes | Escuchar ๐ถ |
๐ซ๐ท French | "Les Misรฉrables" by Victor Hugo | รcouter ๐ถ |
๐น๐ท Turkish | "Tรผfek, Mikrop ve รelik" by Jared Diamond | Dinle ๐ถ |
NarratorX supports a wide array of languages, making it accessible for many readers around the world! ๐ The currently supported languages are:
- ๐บ๐ธ English (en)
- ๐ช๐ธ Spanish (es)
- ๐ซ๐ท French (fr)
- ๐ฉ๐ช German (de)
- ๐ฎ๐น Italian (it)
- ๐ต๐น Portuguese (pt)
- ๐ต๐ฑ Polish (pl)
- ๐น๐ท Turkish (tr)
- ๐ท๐บ Russian (ru)
- ๐ณ๐ฑ Dutch (nl)
- ๐จ๐ฟ Czech (cs)
- ๐ธ๐ฆ Arabic (ar)
- ๐จ๐ณ Chinese (zh-cn)
- ๐ฏ๐ต Japanese (ja)
- ๐ญ๐บ Hungarian (hu)
- ๐ฐ๐ท Korean (ko)
With NarratorX, the world of audiobooks is just a language selection away! ๐๐๐ถ
Here's what's on the horizon:
- Enhanced LLM Options: Integration with additional open-source LLMs and libraries.
- Custom TTS Voices: Support for custom TTS voices and accents.
- Enhanced Chunking and OCR: I am planning to move to open-parse for better OCR results.
- Support for additional file formats: EPUB, DOCX, Image, and plain text support.
- Automated Chunk Size Optimization: Automatically adjust chunk sizes based on model capabilities and language requirements.
- Improved UI/UX: Enhancements to the Streamlit app for a more intuitive user experience.
- Add a stopping option.
- Add step-wise processing - OCR, LLM, TTS.
I welcome all contributions! If you have ideas, suggestions, or want to contribute, feel free to reach out.
Before you begin, ensure you have the following installed:
- Python 3.8 or higher: Download Python
- Poetry: A tool for dependency management.
pip install poetry
- CUDA (Optional): For GPU acceleration with CUDA-compatible GPUs. This can significantly speed up processing times.
-
Clone the Repository
Start by cloning the NarratorX repository to your local machine:
git clone https://github.com/bedirt/narratorx.git cd narratorx
-
Install Dependencies
Use Poetry to install all required dependencies:
poetry install
-
Set Up Environment Variables
NarratorX can work with both OpenAI's GPT models and local open-source LLMs via the Ollama library.
-
If you want to use OpenAI Models:
Obtain your OpenAI API key and set it as an environment variable:
export OPENAI_API_KEY='your-openai-api-key'
-
-
(Optional - Just for Contributing) Install Pre-commit Hooks
If you plan to contribute to NarratorX, set up pre-commit hooks to maintain code quality:
pre-commit install
I implemented two ways to use NarratorX. You can choose between the command-line interface for quick operations or the Streamlit web app for a more interactive experience.
Convert your PDF to an audiobook directly from the terminal:
narratorx path/to/yourfile.pdf --output output.wav --language en --model gpt-4o --log-level INFO
Parameters Explained:
path/to/yourfile.pdf
: The path to the PDF you wish to convert.--output, -o
: (Optional) The path where the output audio file will be saved. Defaults tooutput.wav
.--language, -l
: (Optional) The language code of your PDF content (e.g.,en
for English,tr
for Turkish).--model, -m
: (Optional) The LLM model to use. Options includegpt-4o
,gpt-4o-mini
, or any model supported by the Ollama library likellama3.1
. You can see ollama models here. Do not forget to useollama/
prefix for ollama models.--max-characters-llm
: (Optional) Maximum characters per LLM chunk. Adjust based on model capabilities. 2-4k is a good starting point.--max-tokens
: (Optional) Maximum tokens per LLM call. Adjust based on model capabilities. 2-4k is a good starting point again.--max-characters-tts
: (Optional) Maximum characters per TTS chunk. This value should be changed based on the language you are using, if you get a warningWarning: The text length exceeds the character limit of 239 for language 'es', this might cause truncated audio.
you should decrese this value to be the same as the warning message. (I will automate this soon, lazy at the moment :))--log-level
: (Optional) Set the logging level (DEBUG
,INFO
,WARNING
,ERROR
,CRITICAL
).
Example:
Using an open-source LLM with Ollama:
narratorx path/to/yourfile.pdf --output output.wav --language en --model ollama/llama3.1 --log-level INFO
For a more user-friendly interface, use the Streamlit app:
streamlit run streamlit_app.py
Open your web browser and navigate to http://localhost:8501
. Here, you can:
- Upload your PDF file (up to 200MB).
- Select the language and preferred LLM model.
- Adjust advanced settings such as chunk sizes (optional).
- Monitor the progress of each processing step.
- Listen to a preview and download the final audiobook.
Love contributions! Whether it's bug fixes, new features, or documentation improvements, your help is invaluable, and I appreciate it.
To maintain code quality and consistency, please adhere to the following guidelines:
-
Code Formatting: Use
black
for code formatting with a line length of 100 characters. This ensures that all code follows a consistent style.black --line-length 100 .
-
Import Sorting: Use
isort
with theblack
profile to sort imports correctly.isort --profile black .
-
Linting: Use
flake8
to lint your code and catch potential issues.flake8
-
Pre-commit Hooks: We have pre-commit hooks set up to automate these checks before each commit. Install them with:
pre-commit install
Pre-commit Configuration:
repos: - repo: local hooks: - id: black name: black entry: poetry run black --line-length 100 --exclude '.venv/*' language: system types: [python] - id: flake8 name: flake8 entry: poetry run flake8 --exclude .venv --config .flake8 language: system types: [python] - id: isort name: isort entry: poetry run isort --profile black --skip .venv language: system types: [python]
You can ignore all others, and just install pre-commit hooks with the command above, and (since I already have the configuration file) you can use
pre-commit run --all-files
to run all checks.
Ensure your changes don't break existing functionality by running tests:
-
Install Test Dependencies
poetry install --with dev
-
Run Tests
python -m unittest discover tests/
-
Test Specific Modules
python -m unittest tests/test_llm.py
-
Fork the Repository
Click the "Fork" button at the top right corner of the repository page.
-
Clone Your Fork
git clone https://github.com/yourusername/narratorx.git cd narratorx
-
Create a New Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
Write code, fix bugs, or improve documentation.
-
Format and Lint Your Code
black --line-length 100 . isort --profile black . flake8
or simply:
pre-commit run --all-files
-
Commit Your Changes
git add . git commit -m "Add your descriptive commit message here"
-
Push to Your Fork
git push origin feature/your-feature-name
-
Open a Pull Request
Go to the original repository and open a pull request. Provide a clear description of your changes.
NarratorX is licensed under the GNU General Public License v3.0. By contributing to this project, you agree that your contributions will be licensed under its GPLv3.
See the LICENSE file for more details.
I made use of the following libraries and tools to build NarratorX and am grateful for all their contributions:
Thank you for using NarratorX! I am excited to see how you transform your reading experience. If you have any questions, suggestions, or need assistance, feel free to open an issue or reach out.
You can add me on goodreads here.
Happy listening! ๐ง๐