Skip to content

๐Ÿ“– NarratorX: Turn your PDFs into captivating audiobooks in 16 languages, powered by OCR, LLMs, and expressive TTS. Listen your way! ๐ŸŽงโœจ

License

Notifications You must be signed in to change notification settings

BedirT/NarratorX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NarratorX Banner

Transform your PDFs into engaging audiobooks with the power of OCR, LLMs, and TTS in 16 languages.

License Python Version

Table of Contents

Introduction

๐ŸŽ‰ 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! ๐ŸŽงโœจ

Features

๐Ÿš€ 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

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 ๐ŸŽถ

Supported Languages ๐ŸŒ

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! ๐ŸŒŽ๐Ÿ“–๐ŸŽถ

Roadmap

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.


Installation

Prerequisites

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.

Steps

  1. Clone the Repository

    Start by cloning the NarratorX repository to your local machine:

    git clone https://github.com/bedirt/narratorx.git
    cd narratorx
  2. Install Dependencies

    Use Poetry to install all required dependencies:

    poetry install
  3. 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'
  4. (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

Usage

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.

Command-Line Interface

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 to output.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 include gpt-4o, gpt-4o-mini, or any model supported by the Ollama library like llama3.1. You can see ollama models here. Do not forget to use ollama/ 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 warning Warning: 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

Streamlit Web Application

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.

Contributing

Love contributions! Whether it's bug fixes, new features, or documentation improvements, your help is invaluable, and I appreciate it.

Style Guidelines

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 the black 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.

Testing

Ensure your changes don't break existing functionality by running tests:

  1. Install Test Dependencies

    poetry install --with dev
  2. Run Tests

    python -m unittest discover tests/
  3. Test Specific Modules

    python -m unittest tests/test_llm.py

How to Contribute

  1. Fork the Repository

    Click the "Fork" button at the top right corner of the repository page.

  2. Clone Your Fork

    git clone https://github.com/yourusername/narratorx.git
    cd narratorx
  3. Create a New Branch

    git checkout -b feature/your-feature-name
  4. Make Your Changes

    Write code, fix bugs, or improve documentation.

  5. Format and Lint Your Code

    black --line-length 100 .
    isort --profile black .
    flake8

    or simply:

    pre-commit run --all-files
  6. Commit Your Changes

    git add .
    git commit -m "Add your descriptive commit message here"
  7. Push to Your Fork

    git push origin feature/your-feature-name
  8. Open a Pull Request

    Go to the original repository and open a pull request. Provide a clear description of your changes.


License

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.


Acknowledgements

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! ๐ŸŽง๐Ÿ“–

About

๐Ÿ“– NarratorX: Turn your PDFs into captivating audiobooks in 16 languages, powered by OCR, LLMs, and expressive TTS. Listen your way! ๐ŸŽงโœจ

Topics

Resources

License

Stars

Watchers

Forks

Languages