No description
- Python 100%
| tests | ||
| .gitignore | ||
| config.yaml.example | ||
| LICENSE | ||
| pdf-to-speech.py | ||
| pdf-to-text.py | ||
| README.md | ||
| requirements.txt | ||
| screenplay_tts.py | ||
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
- Clone the repository:
git clone https://gitlab.com/anuna/pdf-to-speech
cd pdf-to-speech
- Install required packages:
pip install -r requirements.txt
- Set up configuration:
- Copy
config.yaml.exampletoconfig.yaml - Add your API keys and configuration details
- Copy
Configuration
You can configure the tool either through environment variables or the config.yaml file:
-
Copy the example configuration file:
cp config.yaml.example config.yaml -
Edit
config.yamland add your:- Google Cloud credentials file path
- OpenAI API key
- Any other custom settings
-
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
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request