Overview
The module handles:- Text-to-speech conversion using ElevenLabs API
- Cloned voice support for personalized narration
- Winner announcement script generation
- Audio file management (MP3 format)
- Voice configuration and quality settings
Requires an ElevenLabs API key. Sign up at elevenlabs.io to get started.
Configuration
Environment Variables
Your ElevenLabs API key for authentication
Optional custom voice ID. Defaults to Rachel (ElevenLabs default voice) if not provided.
Configuration Functions
Core Functions
generate_audio
Convert text to speech using ElevenLabs API.Parameters
The text to convert to speech. Can be multi-line with natural pauses.
Optional path to save the generated MP3 file. Parent directories are created automatically.
Optional voice ID to use. Overrides
ELEVENLABS_CLONED_VOICE_ID env var.Defaults to Rachel (ID: EXAVITQu4vr4xnSDxMaL) if not provided.Returns
MP3 audio data as bytes if successful,
None if API key not configured or request failedExample
generate_winner_script
Generate a narration script for the winner announcement.Parameters
The name of the winning agent (e.g., “Agent Gamma”)
The final winning score (0-100)
The original objective from the Dreamcatcher phase
Returns
Formatted narration script ready for text-to-speech conversion
Example
generate_winner_audio
Convenience function that generates script and audio in one call.Parameters
The name of the winning agent
The final winning score (0-100)
The original objective
Optional path to save the MP3 file
Returns
MP3 audio data if successful,
None otherwiseExample
Voice Configuration
The module uses the following voice settings for optimal narration quality:Voice Parameters
The ElevenLabs model to use.
eleven_monolingual_v1 provides high-quality English narration.Controls voice consistency (0.0-1.0). Higher = more consistent, lower = more expressive.
How closely to match the original voice (0.0-1.0). Higher = closer match to cloned voice.
Available Voices
Default Voices
ID:
EXAVITQu4vr4xnSDxMaLProfessional, clear female voice. Used as default if no custom voice is configured.ID:
TxGEqnHWrfWFTfGW9XjXDeep, authoritative male voice.ID:
EXAVITQu4vr4xnSDxMaLSoft, friendly female voice.Custom Voices
To use a cloned voice:- Visit ElevenLabs Voice Lab
- Create or clone a voice
- Copy the Voice ID
- Add to
.env:
Error Handling
The module uses graceful degradation - if ElevenLabs is not configured or fails, it returns
None rather than raising exceptions.Audio Output
Format Specifications
MP3 (MPEG Audio Layer 3)
Variable (optimized by ElevenLabs)
44.1 kHz (CD quality)
Mono
File Management
Best Practices
Script Length: Keep narration under 2 minutes for optimal listener engagement.
Punctuation: Use periods and commas to create natural pauses in the narration.
Voice Selection: Test different voices to find the best match for your brand tone.
Error Handling: Always check for
None return values before using audio data.