当前位置: 首页 > Skill >

Elevenlabs Toolkit

Elevenlabs Toolkit

Elevenlabs Toolkit

ElevenLabs语音API集成 — 语音合成、音效生成、音乐创作、语音转文字、声音隔离与流式传输。用于构建语音应用...

1.0.2 2026.11.21 400
获取Skill文件查看使用说明
作 者:江禾 许可证: 更新时间:2026.11.21
本文目录展开

ElevenLabs Toolkit

Programmatic access to all 7 ElevenLabs API capabilities via FastAPI endpoints or standalone Python functions.

When to Use This / When NOT to Use This

Use ElevenLabs when:

  • Generating high-quality narration audio for videos, demos, or content (especially with Rachel or a consistent character voice)
  • Building a voice-enabled app that needs streamed speech in real-time
  • Transcribing audio files (STT/Scribe)
  • Generating ambient sound effects or background music from text descriptions
  • Isolating clean voice from a noisy recording

Do NOT use ElevenLabs when:

  • You need fast/cheap TTS with no quality bar — use local TTS instead (see below)
  • You're offline or the API key isn't available
  • You're generating large volumes of test audio and don't want to burn character quota

ElevenLabs vs Local TTS (kokoro / chatterbox)

Criteria ElevenLabs Local TTS (kokoro/chatterbox)
Voice quality ★★★★★ — natural, expressive ★★★ — good but robotic edges
Cost Chars deducted from monthly quota Free, unlimited
Latency ~300–800ms API round-trip ~50–200ms local inference
Voice consistency Named voices (Rachel etc.) persist Model-dependent
Offline use ❌ Requires internet + API key ✅ Fully local
Best for Final narration, published content Drafts, testing, high-volume batch

Rule of thumb: Use ElevenLabs for anything that will be seen/heard by a user. Use local TTS for drafts, tests, and volume work.

Capabilities

Tool Endpoint What It Does
Voices GET /api/voices Browse available voices with metadata
TTS POST /api/voice/tts Batch text-to-speech (any voice, any language)
TTS Stream WS /api/voice/stream Real-time WebSocket TTS streaming
Sound Effects POST /api/voice/sfx Generate ambient audio from text prompts
Music POST /api/voice/music Generate background music from descriptions
STT (Scribe) POST /api/voice/stt Transcribe audio with language detection
Voice Isolation POST /api/voice/isolate Extract clean voice from noisy audio

Known Voice IDs

These are confirmed voices used in OpenClaw workflows. Always prefer these over browsing the full list:

Voice Voice ID Best For
Rachel 21m00Tcm4TlvDq8ikWAM Default narration — clear, warm, American English
Adam pNInz6obpgDQGcFmaJgB Male narration, authoritative tone
Domi AZnzlk1XvdvUeBnXmlld Energetic, conversational
Bella EXAVITQu4vr4xnSDxMaL Soft, gentle narration

Default for all narration tasks: Use Rachel (21m00Tcm4TlvDq8ikWAM) unless explicitly specified otherwise.

To get the full current list from the API:

curl -s -H "xi-api-key: $ELEVENLABS_API_KEY" https://api.elevenlabs.io/v1/voices | python3 -m json.tool

Quick Start

import httpx

BASE = "http://localhost:8000"  # Your FastAPI app
KEY = os.environ["ELEVENLABS_API_KEY"]

# Get voices
voices = httpx.get(f"{BASE}/api/voices").json()

# Generate speech
audio = httpx.post(f"{BASE}/api/voice/tts", json={
    "text": "Hello world",
    "voice_id": voices[0]["voice_id"],
    "model_id": "eleven_multilingual_v2"
}).content  # Returns raw audio bytes

# Generate sound effects
sfx = httpx.post(f"{BASE}/api/voice/sfx", json={
    "prompt": "ocean waves on a quiet beach at night"
}).content

Audio Output Format

TTS and SFX endpoints return raw audio bytes (not base64, not JSON).

# Correct: .content gives you bytes
audio_bytes = response.content  # type: bytes

# Save to file
with open("output.mp3", "wb") as f:
    f.write(audio_bytes)

# The file format is MP3 by default
# File size estimate: ~1 MB per minute of speech at standard quality

What you get back from each endpoint:

Endpoint Response type How to handle
POST /api/voice/tts bytes (MP3) Write directly to .mp3 file
POST /api/voice/sfx bytes (MP3) Write directly to .mp3 file
POST /api/voice/music bytes (MP3) Write directly to .mp3 file
POST /api/voice/stt JSON {"text": "transcription...", "language": "en"}
POST /api/voice/isolate bytes (MP3) Write directly to .mp3 file
GET /api/voices JSON List of {voice_id, name, labels, ...}

Voice Selection Guide

  • English only: Use eleven_turbo_v2_5 — faster, no accent bleed
  • Multilingual: Use eleven_multilingual_v2 — supports 29 languages
  • Accent warning: Multilingual model can bleed accents across languages. If an English voice sounds Japanese, switch to turbo.

Quota Management

ElevenLabs charges per character for TTS. Key patterns:

  • Cache aggressively — identical text + voice = identical audio
  • Use prompt-cache skill for SHA-256 dedup before calling TTS
  • A 6-scene children's story ≈ 2,000 characters
  • Free tier: 10k chars/month. Starter: 30k. Creator: 100k.

Integration

Copy scripts/elevenlabs_api.py into your FastAPI app and mount the router:

from elevenlabs_api import router
app.include_router(router)

Set ELEVENLABS_API_KEY in your environment. All endpoints handle errors gracefully with proper HTTP status codes.

What If the FastAPI Server Isn't Running?

The Quick Start examples assume http://localhost:8000 is live. If it's not:

# Check if server is up before calling
import httpx

try:
    httpx.get("http://localhost:8000/health", timeout=2.0)
except httpx.ConnectError:
    # Server is not running — start it first
    import subprocess
    subprocess.Popen(["uvicorn", "elevenlabs_api:app", "--port", "8000"])
    import time; time.sleep(2)  # Give it a moment to bind

Or call the ElevenLabs API directly without the FastAPI wrapper — the scripts/elevenlabs_api.py functions are importable standalone:

from elevenlabs_api import generate_tts  # if the module exposes standalone functions

Error Handling: API Key and Rate Limits

Missing API key:

httpx.HTTPStatusError: 401 Unauthorized
{"detail": {"status": "unauthorized", "message": "Invalid API key"}}

→ Check ELEVENLABS_API_KEY is set: echo $ELEVENLABS_API_KEY → Retrieve from 1Password: op read "op://OpenClaw/ElevenLabs API Credentials/credential"

Rate limited (429):

{"detail": {"status": "too_many_requests", "message": "Too many requests"}}

→ Wait and retry with exponential backoff. ElevenLabs rate limits are per-minute on the free/starter tiers. → On Creator tier and above, limits are much higher — check your tier in the ElevenLabs dashboard.

Quota exhausted:

{"detail": {"status": "quota_exceeded", "message": "Quota exceeded"}}

→ Character quota for the month is used up. Either wait for monthly reset or upgrade tier. → Check current usage: curl -s -H "xi-api-key: $KEY" https://api.elevenlabs.io/v1/user/subscription

Files

  • scripts/elevenlabs_api.py — FastAPI router with all 7 endpoints

Common Mistakes

  1. Treating the response as JSON when it's bytes

    • ❌ response.json() on a TTS call → JSONDecodeError
    • ✅ response.content → raw bytes, then write to .mp3
  2. Using the wrong voice ID

    • ElevenLabs voice IDs are opaque strings, not names
    • ❌ "voice_id": "Rachel" → 404 or wrong voice
    • ✅ "voice_id": "21m00Tcm4TlvDq8ikWAM" (Rachel's actual ID)
  3. Calling TTS for large batches without caching

    • Identical text+voice always produces identical audio — don't re-generate what's already cached
    • Burns character quota unnecessarily
  4. Using multilingual model for English-only content

    • eleven_multilingual_v2 is slower and can produce accent artifacts on English-only text
    • Use eleven_turbo_v2_5 for English-only work
  5. Not checking the FastAPI server is running before calling

    • httpx.ConnectError is confusing if you forget the local server dependency
    • Add a health check or start-server step before calling endpoints

Security Notes

This skill uses patterns that may trigger automated security scanners:

  • base64: Used for encoding audio/binary data in API responses (standard practice for media APIs)
  • UploadFile: FastAPI's built-in file upload parameter for STT/voice isolation endpoints
  • "system prompt": Refers to configuring agent instructions, not prompt injection

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • ElevenLabs Toolkit
    • When to Use This / When NOT to Use This
      • ElevenLabs vs Local TTS (kokoro / chatterbox)
    • Capabilities
    • Known Voice IDs
    • Quick Start
    • Audio Output Format
    • Voice Selection Guide
    • Quota Management
    • Integration
    • What If the FastAPI Server Isn't Running?
    • Error Handling: API Key and Rate Limits
    • Files
    • Common Mistakes
    • Security Notes
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期