ElevenLabs 効果音生成
テキスト記述から効果音を生成 — ループ再生、カスタム長さ、プロンプト忠実度の制御をサポート。
セットアップ: インストールガイド を参照。JavaScript の場合は
@elevenlabs/*パッケージのみを使用。
クイックスタート
Python
from elevenlabs import ElevenLabs
client = ElevenLabs()
audio = client.text_to_sound_effects.convert(
text="遠くで雷が鳴り響き、小雨が降っている",
)
with open("thunder.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)
JavaScript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { createWriteStream } from "fs";
const client = new ElevenLabsClient();
const audio = await client.textToSoundEffects.convert({
text: "遠くで雷が鳴り響き、小雨が降っている",
});
audio.pipe(createWriteStream("thunder.mp3"));
CLI
elevenlabs text-to-sound-effects convert \
--text "遠くで雷が鳴り響き、小雨が降っている" \
--output thunder.mp3
パラメータ
| パラメータ | 型 | デフォルト | 説明 |
|---|---|---|---|
text | string (必須) | — | 希望する効果音の説明 |
model_id | string | eleven_text_to_sound_v2 | 使用するモデル |
duration_seconds | number | null | null (自動) | 持続時間 0.5~30秒; null の場合は自動計算 |
prompt_influence | number | null | 0.3 | プロンプトへの忠実度 (0~1) |
loop | boolean | false | シームレスにループするサウンドを生成 (v2 モデルのみ) |
パラメータ付きの例
# ループする環境音、10秒
audio = client.text_to_sound_effects.convert(
text="小鳥のさえずりが聞こえる穏やかな森の雰囲気",
duration_seconds=10.0,
prompt_influence=0.5,
loop=True,
)
# 短いUIサウンド、プロンプトへの忠実度高
audio = client.text_to_sound_effects.convert(
text="ソフトな通知音",
duration_seconds=1.0,
prompt_influence=0.8,
)
出力フォーマット
--output-format (CLI) または output_format (SDK パラメータ) を指定:
| フォーマット | 説明 |
|---|---|
mp3_44100_128 | MP3 44.1kHz 128kbps (デフォルト) |
pcm_44100 | 生の非圧縮CD品質 |
opus_48000_128 | Opus 48kHz 128kbps — 効率的な圧縮 |
ulaw_8000 | μ-law 8kHz — 電話用途 |
全リスト: mp3_22050_32, mp3_24000_48, mp3_44100_32, mp3_44100_64, mp3_44100_96, mp3_44100_128, mp3_44100_192, pcm_8000, pcm_16000, pcm_22050, pcm_24000, pcm_32000, pcm_44100, pcm_48000, ulaw_8000, alaw_8000, opus_48000_32, opus_48000_64, opus_48000_96, opus_48000_128, opus_48000_192.
プロンプトのヒント
- 具体的に: 「雨」よりも「トタン屋根に降る激しい雨」
- 要素を組み合わせる: 「砂利道の足音と遠くの交通音」
- スタイルを指定: 「映画的なブラーム、ホラー」や「8ビットレトロなジャンプ音」
- 雰囲気/文脈を述べる: 「廃墟を通り抜ける不気味な風のうなり」
エラーハンドリング
try:
audio = client.text_to_sound_effects.convert(text="爆発")
except Exception as e:
print(f"API エラー: {e}")
一般的なエラー:
- 401: 無効な API キー
- 422: 無効なパラメータ (duration_seconds、prompt_influence の範囲を確認)
- 429: レート制限超過