Generate high-quality audiobooks from text or text files using the Eleven Labs API.
- Convert text directly to audio
- Convert text files to audiobooks
- Support for multiple voice options
- Easy-to-use command-line interface
- Python API for programmatic usage
- Python 3.7 or higher
- Eleven Labs API key (get one at https://elevenlabs.io)
- Clone this repository:
git clone <your-repo-url>
cd hello-world- Install dependencies:
pip install -r requirements.txt- Set up your API key:
cp .env.example .envEdit .env and add your Eleven Labs API key:
ELEVENLABS_API_KEY=your_api_key_here
Generate audiobook from text:
python audiobook_generator.py --text "Your text here" --output my_audiobook.mp3Generate audiobook from a file:
python audiobook_generator.py --file example.txt --output example.mp3List available voices:
python audiobook_generator.py --list-voicesUse a specific voice:
python audiobook_generator.py --file example.txt --voice <voice-id> --output custom_voice.mp3from audiobook_generator import AudiobookGenerator
# Initialize generator
generator = AudiobookGenerator()
# Generate from text
generator.generate_audiobook(
text="Your text content here",
output_path="output.mp3"
)
# Generate from file
generator.generate_from_file(
input_file="book.txt",
output_path="audiobook.mp3"
)
# List available voices
generator.list_voices()Check out usage_examples.py for more detailed examples including:
- Direct text to audio conversion
- File to audio conversion
- Using custom voices
- Batch processing multiple files
Run the example:
python audiobook_generator.py --file example.txtYou can configure the following options in your .env file:
ELEVENLABS_API_KEY: Your Eleven Labs API key (required)DEFAULT_VOICE_ID: Default voice ID to use (optional, defaults to Rachel)
eleven_monolingual_v1: English-only model (default)eleven_multilingual_v1: Supports multiple languageseleven_turbo_v2: Faster generation with good quality
Specify model with --model flag:
python audiobook_generator.py --file text.txt --model eleven_turbo_v2Generated audiobooks are saved as MP3 files. The output location can be:
- Specified with
--outputflag - Auto-generated based on input filename
- Placed in
output/directory for programmatic usage
API Key Error: Make sure your .env file contains a valid ELEVENLABS_API_KEY
File Not Found: Ensure the input file path is correct and the file exists
Voice ID Error: List available voices with --list-voices and use a valid voice ID
Be aware of Eleven Labs API rate limits and quotas for your subscription tier. Check your usage at https://elevenlabs.io/app/usage
MIT
Contributions are welcome! Please feel free to submit a Pull Request.