Loading...
Loading...
Compare original and translation side by side
Setup: See Installation Guide. For JavaScript, usepackages only.@elevenlabs/*
设置: 查看安装指南。对于JavaScript,仅使用包。@elevenlabs/*
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)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)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"));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 -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.mp3curl -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.mp3| 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模型支持) |
undefinedundefinedundefinedundefinedoutput_format| Format | Description |
|---|---|
| MP3 44.1kHz 128kbps (default) |
| Raw uncompressed CD quality |
| Opus 48kHz 128kbps — efficient compressed |
| μ-law 8kHz — telephony |
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_192output_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_192try:
audio = client.text_to_sound_effects.convert(text="Explosion")
except Exception as e:
print(f"API error: {e}")try:
audio = client.text_to_sound_effects.convert(text="Explosion")
except Exception as e:
print(f"API error: {e}")