executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
elevenlabs-apiIntegrates ElevenLabs API (text-to-speech, voice cloning, speech-to-text, sound effects, audio streaming) using the elevenlabs Python SDK for audio generation applications.
Independent GitHub snapshot · Automated classification · Original documentation governs
name: elevenlabs-api description: Integrates ElevenLabs API (text-to-speech, voice cloning, speech-to-text, sound effects, audio streaming) using the elevenlabs Python SDK for audio generation applications. license: MIT compatibility: opencode metadata: version: "1.0.0" domain: coding triggers: elevenlabs, eleven labs, tts, text to speech, voice cloning, elevenlabs api, how do i use elevenlabs, AI voice archetypes:
Integrates ElevenLabs API using the elevenlabs Python SDK for text-to-speech, voice cloning, speech-to-text, sound effects generation, and audio streaming. When loaded, this skill makes the model implement ElevenLabs API calls with proper authentication, audio handling, and streaming for production voice AI applications.
Use this skill when:
coding-openai-apicoding-openai-apiInitialize the Client — Create an ElevenLabs client with the API key from the ELEVENLABS_API_KEY environment variable. The v1.0+ SDK provides a typed client with separate methods for each API. Checkpoint: Verify by calling client.voices.get_all() to list available voices.
Select a Voice — Use client.voices.get_all() to list available voices, or client.voices.get("voice_id") for a specific voice. Each voice has a voice_id, name, and category. Preview voices before committing to one. Checkpoint: Verify the voice exists and is accessible with your current plan.
Generate TTS — Use client.text_to_speech.convert() for TTS generation. Pass voice_id, text, model_id (e.g., "eleven_multilingual_v2"), and voice_settings (stability, similarity_boost). The output is binary audio data (MP3). Checkpoint: Verify the output is valid audio by checking len(audio_data) — it should be > 1000 bytes.
Stream TTS in Real-Time — Use client.text_to_speech.convert_as_stream() for streaming TTS. This returns audio chunks that can be played incrementally. Use this for conversational AI and low-latency applications. Checkpoint: Verify the stream produces chunks without long pauses (indicates latency issues).
Clone a Voice — Use client.voices.add() with audio files for voice cloning. Provide at least 1 audio sample (3+ recommended) for instant voice cloning, or provide more samples (10+) for professional cloning. Checkpoint: Test the cloned voice with a sample sentence to verify quality.
from __future__ import annotations
from elevenlabs import ElevenLabs
# ❌ BAD — no voice settings, no error handling, assumes default voice
from elevenlabs import generate, play
audio = generate(text="Hello world", voice="Rachel")
play(audio)
# ✅ GOOD — typed client, explicit settings, error handling
client = ElevenLabs() # reads ELEVENLABS_API_KEY from environment
def synthesize_speech(
text: str,
voice_id: str = "21m00Tcm4TlvDq8ikWAM",
stability: float = 0.5,
similarity_boost: float = 0.75,
) -> bytes:
"""Convert text to speech using ElevenLabs.
Args:
text: Text to synthesize (max 5000 characters).
voice_id: ElevenLabs voice ID.
stability: Voice stability (0.0-1.0). Lower = more expressive.
similarity_boost: Voice similarity (0.0-1.0). Higher = more accurate.
Returns:
MP3 audio data as bytes.
Raises:
ValueError: If text exceeds 5000 characters.
RuntimeError: On API failure.
"""
if len(text) > 5000:
raise ValueError(
f"Text exceeds 5000 character limit: {len(text)} characters"
)
try:
audio = client.text_to_speech.convert(
voice_id=voice_id,
text=text,
model_id="eleven_multilingual_v2",
voice_settings={
"stability": stability,
"similarity_boost": similarity_boost,
},
)
return b"".join(audio) # convert generator to bytes
except Exception as e:
raise RuntimeError(f"TTS generation failed: {e}") from e
def save_audio(audio_data: bytes, filepath: str) -> None:
"""Save audio bytes to an MP3 file.
Args:
audio_data: Audio data from synthesize_speech.
filepath: Output file path (should end in .mp3).
"""
with open(filepath, "wb") as f:
f.write(audio_data)
from __future__ import annotations
import io
from elevenlabs import ElevenLabs
client = ElevenLabs()
def stream_tts(text: str, voice_id: str = "21m00Tcm4TlvDq8ikWAM") -> bytes:
"""Stream TTS audio in real-time and accumulate to bytes.
For production use, play each chunk as it arrives for
sub-500ms time-to-first-audio latency.
Args:
text: Text to synthesize.
voice_id: ElevenLabs voice ID.
Returns:
Complete MP3 audio as bytes.
"""
audio_stream = client.text_to_speech.convert_as_stream(
voice_id=voice_id,
text=text,
model_id="eleven_multilingual_v2",
)
chunks: list[bytes] = []
for chunk in audio_stream:
chunks.append(chunk)
# In a real app, feed each chunk to an audio player here
audio_data = b"".join(chunks)
print(f"Generated {len(audio_data)} bytes of audio")
return audio_data
def list_voices() -> list[dict]:
"""List all available voices with their IDs and names.
Returns:
List of dicts with voice_id, name, and category.
"""
response = client.voices.get_all()
return [
{
"voice_id": v.voice_id,
"name": v.name,
"category": v.category,
}
for v in response.voices
]
from __future__ import annotations
from elevenlabs import ElevenLabs
from elevenlabs.api.types import Voice
client = ElevenLabs()
def clone_voice(
name: str,
audio_files: list[bytes],
description: str = "",
) -> Voice:
"""Clone a voice from audio samples.
Args:
name: Name for the cloned voice.
audio_files: List of audio file bytes (MP3/WAV, 3+ recommended).
description: Optional description of the voice.
Returns:
The created Voice object.
Raises:
ValueError: If fewer than 1 audio file provided.
"""
if not audio_files:
raise ValueError("At least one audio file is required for voice cloning.")
voice = client.voices.add(
name=name,
files=audio_files,
description=description or f"Cloned voice: {name}",
)
return voice
def test_cloned_voice(voice_id: str, test_text: str = "Hello, this is my cloned voice.") -> bytes:
"""Test a cloned voice by generating a sample.
Args:
voice_id: The cloned voice's ID.
test_text: Text to speak with the cloned voice.
Returns:
MP3 audio as bytes.
"""
audio = client.text_to_speech.convert(
voice_id=voice_id,
text=test_text,
model_id="eleven_multilingual_v2",
)
return b"".join(audio)
from __future__ import annotations
from elevenlabs import ElevenLabs
client = ElevenLabs()
def generate_sound_effect(
prompt: str,
duration_seconds: float = 5.0,
) -> bytes:
"""Generate a sound effect from a text prompt.
Args:
prompt: Description of the sound (e.g., 'rain falling on a roof').
duration_seconds: Maximum duration in seconds.
Returns:
Generated audio as bytes (MP3).
Raises:
RuntimeError: If generation fails.
"""
try:
audio = client.text_to_sound_effects.convert(
text=prompt,
duration_seconds=duration_seconds,
)
return b"".join(audio)
except Exception as e:
raise RuntimeError(f"Sound effect generation failed: {e}") from e
ELEVENLABS_API_KEY environment variableelevenlabs SDK v1.0+ with the typed ElevenLabs() clientvoice_settings (stability, similarity_boost) for consistent voice outputeleven_multilingual_v2 for multilingual TTS (supports 29 languages)generate() top-level function — use client.text_to_speech.convert() instead| Resource | URL |
|---|---|
| ElevenLabs Python SDK (PyPI) | https://pypi.org/project/elevenlabs/ |
| ElevenLabs API Documentation | https://elevenlabs.io/docs |
| ElevenLabs API Reference | https://elevenlabs.io/docs/api-reference |
| ElevenLabs Voice Library | https://elevenlabs.io/voice-library |
| ElevenLabs Sound Effects | https://elevenlabs.io/text-to-sound-effects |
| ElevenLabs GitHub | https://github.com/elevenlabs/elevenlabs-python |
| Skill | Purpose |
|---|---|
coding-openai-api | OpenAI TTS (alternative, fewer voice options) |
coding-stabilityai-api | Stability AI for music/audio generation |