Smart TTS library with ElevenLabs and OpenRouter text enhancement
Project description
elevenlabs-smart-tts
High-level Python library for expressive text-to-speech with ElevenLabs and LLM-powered text enhancement via OpenRouter.
Pass raw text plus task context (language, style, emotion, use case) — the library picks a voice, enriches the text with Eleven v3 audio tags, and returns synthesized audio.
Features
- SmartTTS facade — one pipeline from text to audio
- Voice caching — local
diskcachecatalog with offlinelist_voices()/get_voice() - Automatic voice selection — by
voice_id, description, use case, style, and language - LLM text enhancement — audio tags, punctuation, and normalization via OpenRouter
- Eleven v3 first — expressive tags like
[whispers],[excited],[short pause] - Typed errors & retries — resilient HTTP clients for ElevenLabs and OpenRouter
Installation
pip install elevenlabs-smart-tts
Or from source:
git clone https://github.com/vpuhoff/elevenlabs-smart-tts.git
cd elevenlabs-smart-tts
uv sync --dev
Quick start
- Copy
.env.exampleto.envand fill in your API keys:
cp .env.example .env
- Run synthesis:
from pathlib import Path
from elevenlabs_smart_tts import SmartTTS, SynthesisTask
tts = SmartTTS.from_env()
tts.sync_voices()
result = tts.synthesize_to_file(
SynthesisTask(
text="Welcome to our customer support service.",
language="en",
style="professional",
emotion="warm",
use_case="customer_support",
),
Path("output.mp3"),
)
print(result.enhanced_text)
See example.py for a full runnable example.
Configuration
Required environment variables
| Variable | Description |
|---|---|
ELEVENLABS_API_KEY |
ElevenLabs API key |
OPENROUTER_API_KEY |
OpenRouter API key |
OPENROUTER_API_TTS_PROMPT_MODEL |
LLM for text enhancement (e.g. anthropic/claude-3.5-sonnet) |
Optional environment variables
| Variable | Default | Description |
|---|---|---|
ELEVENLABS_CACHE_DIR |
~/.cache/elevenlabs-smart-tts |
Local cache directory |
ELEVENLABS_DEFAULT_MODEL |
eleven_v3 |
Default TTS model |
ELEVENLABS_DEFAULT_OUTPUT_FORMAT |
mp3_44100_128 |
Audio output format |
ELEVENLABS_DEFAULT_VOICE_ID |
— | Fallback voice when auto-selection fails |
OPENROUTER_BASE_URL |
https://openrouter.ai/api/v1 |
OpenRouter API base URL |
Programmatic configuration is also supported:
from elevenlabs_smart_tts import SmartTTS, SmartTTSConfig, TTSModel
config = SmartTTSConfig(
elevenlabs_api_key="...",
openrouter_api_key="...",
openrouter_tts_prompt_model="anthropic/claude-3.5-sonnet",
default_model=TTSModel.ELEVEN_V3,
)
tts = SmartTTS(config)
Usage
Synthesis pipeline
from elevenlabs_smart_tts import SmartTTS, SynthesisTask, TTSModel
tts = SmartTTS.from_env()
tts.sync_voices()
result = tts.synthesize(
SynthesisTask(
text="Are you serious? I can't believe you did that!",
voice_id="your-voice-id",
model=TTSModel.ELEVEN_V3,
style="dramatic",
emotion="appalled",
)
)
audio_bytes = result.audio
enhanced_text = result.enhanced_text
Preview enhanced text without TTS
enhanced = tts.enhance_text_only(
SynthesisTask(
text="Thanks for calling. How can I help?",
language="en",
style="sympathetic",
)
)
One-liner
from elevenlabs_smart_tts import synthesize
result = synthesize(
"Hello world",
language="en",
style="neutral",
)
Voice management
voices = tts.list_voices(language="en", tags=["narration"])
voice = tts.get_voice("voice-id")
tts.sync_voices(force=True) # refresh cache from ElevenLabs API
Supported TTS models
| Model | Best for |
|---|---|
eleven_v3 |
Expressive speech, audio tags, emotions |
eleven_multilingual_v2 |
Multilingual, high voice similarity |
eleven_flash_v2_5 |
Low latency, conversational agents |
Development
uv sync --dev
uv run pytest
uv run ruff check .
License
MIT — see LICENSE.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elevenlabs_smart_tts-0.1.2.tar.gz.
File metadata
- Download URL: elevenlabs_smart_tts-0.1.2.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bc08b4ad9b7b2f3ecaf73e7e4486b2a57fe51b994bf6d0a429bf7ef5b75b1a8
|
|
| MD5 |
a9a4888f9434d6f27ae512931955d820
|
|
| BLAKE2b-256 |
fef799499e562efe3178ec2d6a8c6ceb280b74747a591ea20e9a8415df76cb96
|
Provenance
The following attestation bundles were made for elevenlabs_smart_tts-0.1.2.tar.gz:
Publisher:
publish.yml on vpuhoff/elevenlabs-smart-tts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
elevenlabs_smart_tts-0.1.2.tar.gz -
Subject digest:
2bc08b4ad9b7b2f3ecaf73e7e4486b2a57fe51b994bf6d0a429bf7ef5b75b1a8 - Sigstore transparency entry: 1685761636
- Sigstore integration time:
-
Permalink:
vpuhoff/elevenlabs-smart-tts@1e78c3341d92dacd07af9e4ef6055d90e6b943b2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/vpuhoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e78c3341d92dacd07af9e4ef6055d90e6b943b2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file elevenlabs_smart_tts-0.1.2-py3-none-any.whl.
File metadata
- Download URL: elevenlabs_smart_tts-0.1.2-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ffa719c20a8954f2a1993f56fd82965cb5c2c05e5a8ff9c697b39c1a191e5e0
|
|
| MD5 |
58713da8725654358d980e506ec20535
|
|
| BLAKE2b-256 |
0a0ac4a832a526c9f9536fbd390108cbd7207174956b8c92c615f742cfda0742
|
Provenance
The following attestation bundles were made for elevenlabs_smart_tts-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on vpuhoff/elevenlabs-smart-tts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
elevenlabs_smart_tts-0.1.2-py3-none-any.whl -
Subject digest:
6ffa719c20a8954f2a1993f56fd82965cb5c2c05e5a8ff9c697b39c1a191e5e0 - Sigstore transparency entry: 1685761705
- Sigstore integration time:
-
Permalink:
vpuhoff/elevenlabs-smart-tts@1e78c3341d92dacd07af9e4ef6055d90e6b943b2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/vpuhoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e78c3341d92dacd07af9e4ef6055d90e6b943b2 -
Trigger Event:
push
-
Statement type: