A type-safe, async Rust client for the ElevenLabs Sound Effects API. Generate high-quality sound effects with a simple, ergonomic API.
- Type-safe & Async: Built with Rust's type system and async/await support
- Builder Pattern: Intuitive, chainable API for configuring SFX requests
- Customizable: Output formats, Duration seconds and Prompt influence
- Tokio Ready: Works seamlessly with the Tokio runtime
This project is part of a milestone to implement all ElevenLabs APIs in Rust.
- Elevenlabs TTS: ElevenLabs Text-to-Speech API. ✅
- Elevenlabs STT: ElevenLabs Speech-to-Text API. ✅
- Elevenlabs TTD: ElevenLabs Text-to-Dialogue API. ✅
- Elevenlabs TTV: ElevenLabs Text-to-Voice API. ✅
- Elevenlabs TTM: ElevenLabs Text-to-Music API. ✅
- Elevenlabs SFX: ElevenLabs Sound Effects API. ✅
- Elevenlabs VC: ElevenLabs Voice Changer API. ✅
- Elevenlabs AUI: ElevenLabs Audio Isolation API. ⏳
- Elevenlabs DUB: ElevenLabs Dubbing API. ⏳
Add this to your Cargo.toml:
[dependencies]
elevenlabs_sfx = "0.0.6"use elevenlabs_sfx::ElevenLabsSFXClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ElevenLabsSFXClient::new("your-api-key");
let audio = client
.sound_effects("Ghost Breath Wind")
.execute()
.await?;
std::fs::write("output.mp3", audio)?;
Ok(())
}use elevenlabs_sfx::ElevenLabsSFXClient;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("ELEVENLABS_API_KEY")?;
let client = ElevenLabsSFXClient::new(api_key);
let audio = client
.sound_effects("Orange juice pouring into the glass")
.execute()
.await?;
let audio_id = chrono::Utc::now().timestamp();
let file_name = format!("outputs/{}.mp3", audio_id);
std::fs::write(file_name.clone(), &audio)?;
println!("Audio saved to {}", file_name);
Ok(())
}use elevenlabs_sfx::ElevenLabsSFXClient;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("ELEVENLABS_API_KEY")?;
let client = ElevenLabsSFXClient::new(api_key);
let client = ElevenLabsSFXClient::new(api_key);
let prompt = "Whoosh whistle flyby air swing swish transition passby bright";
let audio = client
.sound_effects(prompt)
.output_format("mp3_44100_128")
.duration_seconds(4.5)
.prompt_influence(0.75)
.execute()
.await?;
std::fs::create_dir_all("outputs")?;
let audio_id = chrono::Utc::now().timestamp();
let file_name = format!("outputs/{}.mp3", audio_id);
std::fs::write(file_name.clone(), &audio)?;
println!("Audio saved to {}", file_name);
Ok(())
}# Set your API key
export ELEVENLABS_API_KEY=your_api_key_here
# Run the basic example
cargo run --example basic_sfx
# Run the advanced example
cargo run --example advanced_sfx| Method | Description |
|---|---|
ElevenLabsSFXClient::new(String) |
Create client instance (required)* |
.sound_effects(String) |
Build a SFX request (required)* |
.output_format(String) |
Audio format (e.g. mp3_44100) (optional) |
.duration_seconds(f32) |
Duration in seconds (0.5 - 22.0) (optional) |
.prompt_influence(f32) |
Prompt adherence strength (0.0 - 1.0) (optional) |
.execute() |
Run request → audio (required)* |
The crate uses standard Rust error handling patterns. All async methods return Result types:
match client.sound_effects("Ghost Breath Wind").execute().await {
Ok(audio) => println!("Generated {} bytes of audio", audio.len()),
Err(e) => eprintln!("SFX generation failed: {}", e),
}- Rust 1.70+ (for async/await support)
- Tokio runtime
- Valid ElevenLabs API key
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to:
- Open issues for bugs or feature requests
- Submit pull requests with improvements
- Improve documentation or examples
- Add tests or benchmarks
Before contributing, please ensure your code follows Rust conventions and includes appropriate tests.
If you like this project, consider supporting me on Patreon 💖
See CHANGELOG.md for a detailed history of changes.
Note: This crate is not officially affiliated with ElevenLabs. Please refer to the ElevenLabs API documentation for the most up-to-date API information.