sound-effects
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseElevenLabs Sound Effects
ElevenLabs 音效生成
Generate sound effects from text descriptions — supports looping, custom duration, and prompt adherence control.
Setup: See Installation Guide. For JavaScript, usepackages only.@elevenlabs/*
根据文本描述生成音效——支持循环播放、自定义时长和提示词贴合度控制。
设置: 查看安装指南。对于JavaScript,仅使用包。@elevenlabs/*
Quick Start
快速开始
Python
Python
python
from elevenlabs.client import ElevenLabs
client = ElevenLabs()
audio = client.text_to_sound_effects.convert(
text="Thunder rumbling in the distance with light rain",
)
with open("thunder.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)python
from elevenlabs.client import ElevenLabs
client = ElevenLabs()
audio = client.text_to_sound_effects.convert(
text="Thunder rumbling in the distance with light rain",
)
with open("thunder.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)JavaScript
JavaScript
javascript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { createWriteStream } from "fs";
const client = new ElevenLabsClient();
const audio = await client.textToSoundEffects.convert({
text: "Thunder rumbling in the distance with light rain",
});
audio.pipe(createWriteStream("thunder.mp3"));javascript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { createWriteStream } from "fs";
const client = new ElevenLabsClient();
const audio = await client.textToSoundEffects.convert({
text: "Thunder rumbling in the distance with light rain",
});
audio.pipe(createWriteStream("thunder.mp3"));cURL
cURL
bash
curl -X POST "https://api.elevenlabs.io/v1/sound-generation" \
-H "xi-api-key: $ELEVENLABS_API_KEY" -H "Content-Type: application/json" \
-d '{"text": "Thunder rumbling in the distance with light rain"}' \
--output thunder.mp3bash
curl -X POST "https://api.elevenlabs.io/v1/sound-generation" \
-H "xi-api-key: $ELEVENLABS_API_KEY" -H "Content-Type: application/json" \
-d '{"text": "Thunder rumbling in the distance with light rain"}' \
--output thunder.mp3Parameters
参数
| Parameter | Type | Default | Description |
|---|---|---|---|
| string (required) | — | Description of the desired sound effect |
| string | | Model to use |
| number | null | null (auto) | Duration 0.5–30s; auto-calculated if null |
| number | null | 0.3 | How closely to follow the prompt (0–1) |
| boolean | false | Generate a seamlessly looping sound (v2 model only) |
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 字符串(必填) | — | 所需音效的描述 |
| 字符串 | | 使用的模型 |
| 数字 | null | null(自动) | 时长0.5–30秒;若为null则自动计算 |
| 数字 | null | 0.3 | 遵循提示词的程度(0–1) |
| 布尔值 | false | 生成可无缝循环的音效(仅v2模型支持) |
Examples with Parameters
带参数的示例
python
undefinedpython
undefinedLooping ambient sound, 10 seconds
Looping ambient sound, 10 seconds
audio = client.text_to_sound_effects.convert(
text="Gentle forest ambiance with birds chirping",
duration_seconds=10.0,
prompt_influence=0.5,
loop=True,
)
audio = client.text_to_sound_effects.convert(
text="Gentle forest ambiance with birds chirping",
duration_seconds=10.0,
prompt_influence=0.5,
loop=True,
)
Short UI sound, high prompt adherence
Short UI sound, high prompt adherence
audio = client.text_to_sound_effects.convert(
text="Soft notification chime",
duration_seconds=1.0,
prompt_influence=0.8,
)
undefinedaudio = client.text_to_sound_effects.convert(
text="Soft notification chime",
duration_seconds=1.0,
prompt_influence=0.8,
)
undefinedOutput Formats
输出格式
Pass as a query parameter (cURL) or SDK parameter:
output_format| Format | Description |
|---|---|
| MP3 44.1kHz 128kbps (default) |
| Raw uncompressed CD quality |
| Opus 48kHz 128kbps — efficient compressed |
| μ-law 8kHz — telephony |
Full list: , , , , , , , , , , , , , , , , , , , , .
mp3_22050_32mp3_24000_48mp3_44100_32mp3_44100_64mp3_44100_96mp3_44100_128mp3_44100_192pcm_8000pcm_16000pcm_22050pcm_24000pcm_32000pcm_44100pcm_48000ulaw_8000alaw_8000opus_48000_32opus_48000_64opus_48000_96opus_48000_128opus_48000_192传递作为查询参数(cURL)或SDK参数:
output_format| 格式 | 说明 |
|---|---|
| MP3 44.1kHz 128kbps(默认) |
| 原始无压缩CD音质 |
| Opus 48kHz 128kbps — 高效压缩格式 |
| μ-law 8kHz — 电话音质 |
完整列表:, , , , , , , , , , , , , , , , , , , , .
mp3_22050_32mp3_24000_48mp3_44100_32mp3_44100_64mp3_44100_96mp3_44100_128mp3_44100_192pcm_8000pcm_16000pcm_22050pcm_24000pcm_32000pcm_44100pcm_48000ulaw_8000alaw_8000opus_48000_32opus_48000_64opus_48000_96opus_48000_128opus_48000_192Prompt Tips
提示词技巧
- Be specific: "Heavy rain on a tin roof" > "Rain"
- Combine elements: "Footsteps on gravel with distant traffic"
- Specify style: "Cinematic braam, horror" or "8-bit retro jump sound"
- Mention mood/context: "Eerie wind howling through an abandoned building"
- 具体明确:"Heavy rain on a tin roof"(铁皮屋顶上的大雨)优于"Rain"(雨)
- 组合元素:"Footsteps on gravel with distant traffic"(砾石上的脚步声加远处的车流声)
- 指定风格:"Cinematic braam, horror"(电影式低沉轰鸣,恐怖风格)或"8-bit retro jump sound"(8位复古跳跃音效)
- 提及情绪/场景:"Eerie wind howling through an abandoned building"(废弃建筑中呼啸的诡异风声)
Error Handling
错误处理
python
try:
audio = client.text_to_sound_effects.convert(text="Explosion")
except Exception as e:
print(f"API error: {e}")Common errors:
- 401: Invalid API key
- 422: Invalid parameters (check duration range, prompt_influence range)
- 429: Rate limit exceeded
python
try:
audio = client.text_to_sound_effects.convert(text="Explosion")
except Exception as e:
print(f"API error: {e}")常见错误:
- 401:无效的API密钥
- 422:参数无效(检查时长范围、prompt_influence范围)
- 429:超出调用频率限制
References
参考资料
- Installation Guide
- 安装指南