Generate sound effects from text descriptions for videos, games, podcasts, and voice-overs. Create custom audio effects by describing the sound you need in natural language.
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
const client = new ElevenLabsClient({ apiKey: "your-api-key" });
// Access this API via: client.textToSoundEffectsCreate sound effects from text prompts.
/**
* @param request - Sound effect description and settings
* @param requestOptions - Optional request configuration
* @returns ReadableStream of audio chunks
* @throws UnprocessableEntityError if request fails
*/
client.textToSoundEffects.convert(
request: CreateSoundEffectRequest,
requestOptions?: RequestOptions
): HttpResponsePromise<ReadableStream<Uint8Array>>;
interface CreateSoundEffectRequest {
/** Text description of the sound effect */
text: string;
/** Duration hint in seconds (optional) */
duration_seconds?: number;
/** Prompt influence (0.0 to 1.0, higher = more adherence to prompt) */
prompt_influence?: number;
}import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { writeFile } from "fs/promises";
const client = new ElevenLabsClient({ apiKey: "your-api-key" });
// Generate a simple sound effect
const soundEffect = await client.textToSoundEffects.convert({
text: "Dog barking",
});
// Save to file
const chunks: Uint8Array[] = [];
for await (const chunk of soundEffect) {
chunks.push(chunk);
}
await writeFile("dog_bark.mp3", Buffer.concat(chunks));// Generate sound effect with specific duration
const explosion = await client.textToSoundEffects.convert({
text: "Large explosion with debris falling",
duration_seconds: 3.5,
});// Higher prompt influence = more faithful to description
const doorCreak = await client.textToSoundEffects.convert({
text: "Old wooden door slowly creaking open",
prompt_influence: 0.9, // Very faithful to prompt
});
// Lower prompt influence = more creative interpretation
const ambientNoise = await client.textToSoundEffects.convert({
text: "Futuristic space station ambience",
prompt_influence: 0.3, // More creative freedom
});// Generate various game sound effects
const gameSounds = [
"Coin pickup sound with a cheerful ding",
"Sword swinging through air",
"Magic spell casting with sparkles",
"Player taking damage, painful grunt",
"Victory fanfare with trumpets",
"Footsteps on wooden floor",
"Door opening, metal hinges squeaking",
"Treasure chest opening",
];
for (const soundDescription of gameSounds) {
const audio = await client.textToSoundEffects.convert({
text: soundDescription,
});
// Save each sound effect
const filename = soundDescription
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
.substring(0, 50) + ".mp3";
const chunks: Uint8Array[] = [];
for await (const chunk of audio) {
chunks.push(chunk);
}
await writeFile(`sounds/${filename}`, Buffer.concat(chunks));
console.log(`Generated: ${filename}`);
}// Generate environmental and atmospheric sounds
async function generateEnvironmentalSound(
environment: string
): Promise<Buffer> {
const audio = await client.textToSoundEffects.convert({
text: `Ambient ${environment} atmosphere`,
duration_seconds: 10,
});
const chunks: Uint8Array[] = [];
for await (const chunk of audio) {
chunks.push(chunk);
}
return Buffer.concat(chunks);
}
// Generate various environments
const forest = await generateEnvironmentalSound("forest with birds chirping and wind");
const ocean = await generateEnvironmentalSound("ocean waves on beach");
const city = await generateEnvironmentalSound("busy city street with traffic");
const rain = await generateEnvironmentalSound("rain on window with thunder");
await writeFile("forest_ambience.mp3", forest);
await writeFile("ocean_ambience.mp3", ocean);
await writeFile("city_ambience.mp3", city);
await writeFile("rain_ambience.mp3", rain);// Generate sound effects for video production
const videoSFX = [
{ text: "Camera shutter click", duration: 0.5 },
{ text: "Whoosh transition sound", duration: 1.0 },
{ text: "Pop up notification sound", duration: 0.8 },
{ text: "Paper rustling", duration: 2.0 },
{ text: "Keyboard typing rapidly", duration: 3.0 },
{ text: "Phone ringing", duration: 4.0 },
];
for (const sfx of videoSFX) {
const audio = await client.textToSoundEffects.convert({
text: sfx.text,
duration_seconds: sfx.duration,
});
// Save audio...
}// Generate science fiction sound effects
const scifiSounds = [
"Futuristic laser gun firing",
"Spaceship engine humming",
"Teleportation sound with electronic glitch",
"Robot walking with mechanical servos",
"Force field activation with electric buzz",
"Hologram materializing",
"Alien communication beeps and chirps",
];
for (const sound of scifiSounds) {
const audio = await client.textToSoundEffects.convert({
text: sound,
duration_seconds: 2,
prompt_influence: 0.8,
});
// Process audio...
}// Generate natural sound effects
async function generateNatureSound(description: string): Promise<void> {
const audio = await client.textToSoundEffects.convert({
text: description,
duration_seconds: 5,
});
const filename = description.replace(/\s+/g, "_").toLowerCase() + ".mp3";
const chunks: Uint8Array[] = [];
for await (const chunk of audio) {
chunks.push(chunk);
}
await writeFile(`nature/${filename}`, Buffer.concat(chunks));
}
await generateNatureSound("Birds singing in morning");
await generateNatureSound("Waterfall cascading");
await generateNatureSound("Wind blowing through trees");
await generateNatureSound("Crickets chirping at night");
await generateNatureSound("Thunder rumbling in distance");// Generate musical sound effects
const musicalSFX = await client.textToSoundEffects.convert({
text: "Dramatic drum roll building tension",
duration_seconds: 4,
prompt_influence: 0.9,
});
const cymbalCrash = await client.textToSoundEffects.convert({
text: "Cymbal crash with reverb",
duration_seconds: 2,
});
const glassHarp = await client.textToSoundEffects.convert({
text: "Glass harmonica playing ethereal notes",
duration_seconds: 3,
});// Generate action and impact sounds
const actionSounds = [
{ text: "Punch impact, heavy hit", duration: 0.5 },
{ text: "Glass breaking and shattering", duration: 2 },
{ text: "Car crash with metal crunching", duration: 3 },
{ text: "Running footsteps on gravel", duration: 4 },
{ text: "Door slamming shut", duration: 1 },
];
for (const sound of actionSounds) {
const audio = await client.textToSoundEffects.convert({
text: sound.text,
duration_seconds: sound.duration,
});
// Save audio...
}// Generate sound effects for podcast production
async function generatePodcastSFX(): Promise<void> {
// Intro music element
const intro = await client.textToSoundEffects.convert({
text: "Upbeat podcast intro jingle",
duration_seconds: 5,
});
// Transition sounds
const transition = await client.textToSoundEffects.convert({
text: "Smooth whoosh transition",
duration_seconds: 1,
});
// Notification sound
const notification = await client.textToSoundEffects.convert({
text: "Gentle notification chime",
duration_seconds: 1,
});
// Outro
const outro = await client.textToSoundEffects.convert({
text: "Podcast outro with fade",
duration_seconds: 5,
});
// Save all files...
}// Generate horror/suspense sound effects
const horrorSounds = [
"Creepy whispers echoing",
"Distorted scream fading out",
"Ominous deep rumble building",
"Chains rattling in distance",
"Eerie music box melody slowing down",
"Heavy breathing with heartbeat",
];
for (const sound of horrorSounds) {
const audio = await client.textToSoundEffects.convert({
text: sound,
duration_seconds: 5,
prompt_influence: 0.85,
});
// Process for horror project...
}// Create a complete UI sound library
interface UISoundDefinition {
name: string;
description: string;
duration: number;
}
const uiSounds: UISoundDefinition[] = [
{ name: "button_click", description: "Soft button click", duration: 0.3 },
{ name: "success", description: "Success confirmation chime", duration: 1 },
{ name: "error", description: "Error alert beep", duration: 0.8 },
{ name: "notification", description: "Gentle notification sound", duration: 1 },
{ name: "toggle_on", description: "Toggle switch turning on", duration: 0.4 },
{ name: "toggle_off", description: "Toggle switch turning off", duration: 0.4 },
{ name: "page_flip", description: "Paper page turning", duration: 0.6 },
{ name: "swipe", description: "Swipe whoosh", duration: 0.5 },
];
for (const uiSound of uiSounds) {
const audio = await client.textToSoundEffects.convert({
text: uiSound.description,
duration_seconds: uiSound.duration,
prompt_influence: 0.9,
});
const chunks: Uint8Array[] = [];
for await (const chunk of audio) {
chunks.push(chunk);
}
await writeFile(`ui/${uiSound.name}.mp3`, Buffer.concat(chunks));
console.log(`Created UI sound: ${uiSound.name}`);
}// More detailed descriptions yield better results
const detailedSFX = await client.textToSoundEffects.convert({
text: "A medieval wooden drawbridge slowly lowering with heavy chains rattling, wood creaking under stress, and metal mechanisms groaning",
duration_seconds: 6,
prompt_influence: 0.9,
});
const complexSound = await client.textToSoundEffects.convert({
text: "Busy coffee shop atmosphere with espresso machine hissing, cups clinking, background chatter, and light jazz music",
duration_seconds: 10,
prompt_influence: 0.7,
});