No description
Find a file
Hugo O'Connor 20dcad8b66
add tests
2025-06-25 23:33:39 +10:00
tests add tests 2025-06-25 23:33:39 +10:00
.gitignore feat: pdf-to-speech cli script using google document ai and openai tts 2024-11-26 13:36:50 +11:00
config.yaml.example feat: pdf-to-speech cli script using google document ai and openai tts 2024-11-26 13:36:50 +11:00
LICENSE Update file LICENSE 2024-11-26 02:32:49 +00:00
pdf-to-speech.py feat: pdf-to-speech cli script using google document ai and openai tts 2024-11-26 13:36:50 +11:00
pdf-to-text.py batch process pdf to text 2025-06-19 14:01:14 +10:00
README.md docs: update requirements and readme 2024-11-26 13:45:56 +11:00
requirements.txt feat: pdf-to-text script 2025-03-11 18:37:47 +11:00
screenplay_tts.py add tests 2025-06-25 23:33:39 +10:00

PDF to Speech Converter

A command-line tool that converts PDF documents to speech (an audio file) using Google Document AI and OpenAI's Text-to-Speech API.

(I use this for my book club)

Features

  • Convert PDF files to text using Google Document AI
  • Convert text to speech using OpenAI's TTS API
  • Support for multiple voice models
  • Handles large PDF documents by splitting them into manageable chunks
  • Configurable through YAML configuration file

Prerequisites

  • Python 3.8 or higher
  • Google Cloud account with Document AI API enabled
  • OpenAI API key
  • Required Python packages (see requirements.txt)

Installation

  1. Clone the repository:
git clone https://gitlab.com/anuna/pdf-to-speech
cd pdf-to-speech
  1. Install required packages:
pip install -r requirements.txt
  1. Set up configuration:
    • Copy config.yaml.example to config.yaml
    • Add your API keys and configuration details

Configuration

You can configure the tool either through environment variables or the config.yaml file:

  1. Copy the example configuration file:

    cp config.yaml.example config.yaml
    
  2. Edit config.yaml and add your:

    • Google Cloud credentials file path
    • OpenAI API key
    • Any other custom settings
  3. Required minimum configuration:

    api:
      google:
        credentials_path: "/path/to/your/credentials.json"
      openai:
        api_key: "your-openai-api-key"
    
    

Environment Variables:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"
export OPENAI_API_KEY="your-openai-api-key"

Config File:

Update the config.yaml file with your API keys and preferences.

Usage

Basic usage:

python pdf-to-speech.py -i input.pdf -o output.mp3 -v nova

Options:

  • -i, --input: Input PDF file path (required)
  • -o, --output: Output audio file path (required)
  • -v, --voice: Voice model to use (optional, defaults to 'nova')

Available voice models:

  • alloy
  • echo
  • fable
  • nova
  • onyx
  • shimmer

Examples

Convert a PDF using the default voice:

python pdf_to_speech.py -i documents/sample.pdf -o audio/output.mp3

Convert using a specific voice model:

python pdf_to_speech.py -i documents/sample.pdf -o audio/output.mp3 -v shimmer

License

Apache License Version 2.0

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request