elevenlabs-tts

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ElevenLabs Text-to-Speech

ElevenLabs 文本转语音

Overview

概述

Generate professional audio files from text using ElevenLabs' advanced text-to-speech API. The skill provides pre-configured voice presets with sensible defaults, voice parameter customization, and direct access to the
scripts/elevenlabs_tts.py
script for programmatic control.
借助ElevenLabs先进的文本转语音API,将文本生成为专业级音频文件。该技能提供了配置合理默认值的预设语音、可自定义的语音参数,还可直接访问
scripts/elevenlabs_tts.py
脚本以实现程序化控制。

Quick Start

快速开始

To generate audio from text:
  1. Ensure the
    .env
    file contains a valid
    ELEVENLABS_API_KEY
  2. Execute the script with text:
    python scripts/elevenlabs_tts.py "Your text here"
  3. Specify voice and output:
    python scripts/elevenlabs_tts.py "Text" --voice adam --output audio/output.mp3
要将文本生成音频:
  1. 确保
    .env
    文件包含有效的
    ELEVENLABS_API_KEY
  2. 使用文本执行脚本:
    python scripts/elevenlabs_tts.py "Your text here"
  3. 指定语音和输出路径:
    python scripts/elevenlabs_tts.py "Text" --voice adam --output audio/output.mp3

Voice Presets

预设语音

Seven pre-configured voices are available. See
references/api_reference.md
for complete voice descriptions:
  • rachel
    (default) - Clear, professional female
  • adam
    - Deep, authoritative male
  • bella
    - Warm, friendly female
  • elli
    - Young, enthusiastic female
  • josh
    - Friendly, conversational male
  • arnold
    - Deep, powerful male
  • ava
    - Expressive, dynamic female
提供七种预配置的语音。完整的语音说明请查看
references/api_reference.md
  • rachel
    (默认)- 清晰、专业的女声
  • adam
    - 低沉、权威的男声
  • bella
    - 温暖、友好的女声
  • elli
    - 年轻、热情的女声
  • josh
    - 亲切、口语化的男声
  • arnold
    - 低沉、有力量的男声
  • ava
    - 富有表现力、充满活力的女声

Parameters

参数

Text

文本

The text to convert to speech. Any length is supported.
需要转换为语音的文本。支持任意长度。

Voice Selection

语音选择

Specify voice using preset name (e.g.,
rachel
,
adam
) or direct ElevenLabs voice ID.
可通过预设名称(如
rachel
adam
)或ElevenLabs语音ID指定语音。

Voice Parameters

语音参数

  • stability (0.0-1.0, default 0.5): Lower values create expressive variation; higher values ensure consistency
  • similarity_boost (0.0-1.0, default 0.75): Higher values maintain closer adherence to voice characteristics
  • stability(0.0-1.0,默认值0.5):值越低,语音表现力变化越强;值越高,语音一致性越好
  • similarity_boost(0.0-1.0,默认值0.75):值越高,越贴近原语音特征

Output

输出

Specify the output file path. Default is
output.mp3
. Directories are created automatically.
指定输出文件路径。默认路径为
output.mp3
。目录不存在时会自动创建。

Usage Examples

使用示例

Basic Python Usage

Python基础用法

python
from scripts.elevenlabs_tts import generate_speech

path = generate_speech(
    text="Hello, this is a test message",
    voice_id="rachel"
)
python
from scripts.elevenlabs_tts import generate_speech

path = generate_speech(
    text="Hello, this is a test message",
    voice_id="rachel"
)

Command Line

命令行

bash
undefined
bash
undefined

With default voice

With default voice

python scripts/elevenlabs_tts.py "Generate this text"
python scripts/elevenlabs_tts.py "Generate this text"

With custom voice and stability

With custom voice and stability

python scripts/elevenlabs_tts.py "Different voice" --voice adam --stability 0.7
python scripts/elevenlabs_tts.py "Different voice" --voice adam --stability 0.7

To custom output path

To custom output path

python scripts/elevenlabs_tts.py "Save here" --output audio/narration.mp3
python scripts/elevenlabs_tts.py "Save here" --output audio/narration.mp3

List available voices

List available voices

python scripts/elevenlabs_tts.py "" --list-voices
undefined
python scripts/elevenlabs_tts.py "" --list-voices
undefined

Implementation Notes

实现说明

  • The script handles API communication with error reporting
  • Output directories are created automatically if they don't exist
  • Returns absolute path to generated audio file
  • Uses
    eleven_monolingual_v1
    model by default (can be overridden)
  • 脚本处理API通信并提供错误报告
  • 输出目录不存在时会自动创建
  • 返回生成的音频文件的绝对路径
  • 默认使用
    eleven_monolingual_v1
    模型(可覆盖)

Resources

资源

  • scripts/elevenlabs_tts.py
    - Main Python script for text-to-speech generation. Can be imported as a module or executed from command line.
  • references/api_reference.md
    - Detailed API documentation including voice descriptions, parameter explanations, and usage examples.
  • .env
    and
    .env.example
    - Environment configuration for storing API credentials securely.
  • scripts/elevenlabs_tts.py
    - 用于文本转语音生成的主Python脚本。可作为模块导入或从命令行执行。
  • references/api_reference.md
    - 详细的API文档,包括语音说明、参数解释和使用示例。
  • .env
    .env.example
    - 用于安全存储API凭证的环境配置文件。