| Crates.io | elevenlabs_ttd |
| lib.rs | elevenlabs_ttd |
| version | 0.0.4 |
| created_at | 2025-08-29 13:31:33.517523+00 |
| updated_at | 2025-09-01 17:05:13.394789+00 |
| description | Type-safe Rust client for ElevenLabs Text-to-Dialogue API |
| homepage | |
| repository | https://github.com/hamzaelmarjani/elevenlabs_ttd |
| max_upload_size | |
| id | 1815835 |
| size | 88,576 |
A type-safe, async Rust client for the ElevenLabs Text-to-Dialogue API. Generate high-quality speech-dialog from text with a simple, ergonomic API.
voices::all_voices::*)models::elevenlabs_models::*)This project is part of a milestone to implement all ElevenLabs APIs in Rust.
Add this to your Cargo.toml:
[dependencies]
elevenlabs_ttd = "0.0.4"
use elevenlabs_ttd::ElevenLabsTTDClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ElevenLabsTTDClient::new("your-api-key");
let inputs = vec![
TTDInput {
text: "I saw the sky this morning, it looked like fire.".to_string(),
voice_id: voices::all_voices::ARNOLD.voice_id.to_string(),
},
TTDInput {
text: "I noticed that too, the sunrise was unreal.".to_string(),
voice_id: voices::all_voices::IVANA.voice_id.to_string(),
},
];
let audio = client.text_to_dialogue(inputs).execute().await?;
std::fs::write("outputs.mp3", &audio)?;
Ok(())
}
use elevenlabs_ttd::{ElevenLabsTTDClient, models, voices};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("ELEVENLABS_API_KEY")
.expect("Please set ELEVENLABS_API_KEY environment variable");
let client = ElevenLabsTTDClient::new(api_key);
let inputs = vec![
TTDInput {
text: "I saw the sky this morning, it looked like fire.".to_string(),
voice_id: voices::all_voices::ARNOLD.voice_id.to_string(),
},
TTDInput {
text: "I noticed that too, the sunrise was unreal.".to_string(),
voice_id: voices::all_voices::IVANA.voice_id.to_string(),
},
];
let audio = client.text_to_dialogue(inputs).execute().await?;
std::fs::create_dir_all("outputs")?;
std::fs::write("outputs/output.mp3", audio)?;
println!("Audio saved to outputs/output.mp3");
Ok(())
}
use elevenlabs_ttd::{ElevenLabsTTDClient, models, voices};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("ELEVENLABS_API_KEY")
.expect("Please set ELEVENLABS_API_KEY environment variable");
let client = ElevenLabsTTDClient::new(api_key);
let inputs = vec![
TTDInput {
text: "I saw the sky this morning, it looked like fire.".to_string(),
voice_id: voices::all_voices::ARNOLD.voice_id.to_string(),
},
TTDInput {
text: "I noticed that too, the sunrise was unreal.".to_string(),
voice_id: voices::all_voices::IVANA.voice_id.to_string(),
},
];
let settings = elevenlabs_ttd::TTDSettings::new()
.stability(0.5)
.speaker_boost(true);
let audio = client
.text_to_dialogue(inputs)
.model(models::elevanlabs_models::ELEVEN_V3)
.output_format("mp3_44100_128")
.settings(settings)
.seed(4000)
.execute()
.await?;
std::fs::create_dir_all("outputs")?;
std::fs::write("outputs/output.mp3", audio)?;
println!("Audio saved to outputs/output.mp3");
Ok(())
}
# Set your API key
export ELEVENLABS_API_KEY=your_api_key_here
# Run the basic example
cargo run --example basic_ttd
# Run the advanced example
cargo run --example advanced_ttd
| Method | Description |
|---|---|
ElevenLabsTTDClient::new(String) |
Create client instance (required)* |
.text_to_dialogue(String) |
Build a TTD request (required)* |
.inputs(TTDInput) |
A list of dialogue inputs, each containing text & a voice_id (required)* |
.output_format(String) |
Audio format (e.g. mp3_44100) (optional) |
.model_id(String) |
Only Eleven V3 Family Supported for now (optional) |
.settings(TTDSettings) |
Settings controlling the dialogue generation. (optional) |
.pronunciation_dictionary_locators(TTDPronunciationDictionaryLocators) |
A list of pronunciation dictionary locators (id, version_id) to be applied to the text (optional) |
.seed(u32) |
Deterministic sampling (optional) |
.execute() |
Run request → audio (required)* |
The crate uses standard Rust error handling patterns. All async methods return Result types:
match client.text_to_dialogue(inputs).execute().await {
Ok(audio) => println!("Generated {} bytes of audio", audio.len()),
Err(e) => eprintln!("TTD generation failed: {}", e),
}
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to:
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.