elevenlabs_vc

Crates.ioelevenlabs_vc
lib.rselevenlabs_vc
version0.0.4
created_at2025-08-30 02:05:51.094675+00
updated_at2025-09-01 17:03:24.397702+00
descriptionType-safe Rust client for ElevenLabs Voice Changer API
homepage
repositoryhttps://github.com/hamzaelmarjani/elevenlabs_vc
max_upload_size
id1817169
size91,009
Hamza El Marjani (hamzaelmarjani)

documentation

README

elevenlabs_vc

Crates.io Docs.rs License

A type-safe, async Rust client for the ElevenLabs Voice Changer API. Transform audio from one voice to another. Maintain full control over emotion, timing and delivery, with simple Ergonomic API.

Features

  • Type-safe & Async: Built with Rust's type system and async/await support
  • Builder Pattern: Intuitive, chainable API for configuring VC requests
  • Predefined Voices: Access to static voice definitions (voices::all_voices::*)
  • Model Support: Full support for ElevenLabs models (models::elevenlabs_models::*)
  • Customizable: Elevanlabs STT APIs, custom base URLs, and enterprise support
  • Tokio Ready: Works seamlessly with the Tokio runtime
  • Audio Only: Works with audios only, up to 50MB

Check-out Also:

This project is part of a milestone to implement all ElevenLabs APIs in Rust.

Installation

Add this to your Cargo.toml:

[dependencies]
elevenlabs_vc = "0.0.4"

Quick Start

use elevenlabs_vc::{ElevenLabsVCClient, voices};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ElevenLabsVCClient::new("your-api-key");

    let file_path = "inputs/speech.mp3";
    let file_content = std::fs::read(file_path)?;

    let audio = client.voice_changer([].to_vec(), voices::all_voices::PAUL.voice_id).execute().await?;

    std::fs::write("output.mp3", &audio)?;

    Ok(())
}

Examples

Basic Usage

use elevenlabs_vc::{ElevenLabsVCClient, 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 = ElevenLabsVCClient::new(api_key);

    let file_path = "inputs/input.mp3";
    let file_content = std::fs::read(file_path)?;

    let audio = client
        .voice_changer(file_content, voices::all_voices::PAUL.voice_id)
        .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)?;

    Ok(())
}

Advanced Configuration

use elevenlabs_vc::{ElevenLabsVCClient, VoiceSettings, 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 = ElevenLabsVCClient::new(api_key);

    let file_path = "inputs/input.mp3";
    let file_content = std::fs::read(file_path)?;

    let audio = client
        .voice_changer(file_content, voices::all_voices::PAUL.voice_id)
        .model(models::elevanlabs_models::ELEVEN_MULTILINGUAL_STS_V2)
        .remove_background_noise(true)
        .seed(2500)
        .voice_settings(
            VoiceSettings::default()
                .stability(0.5)
                .speaker_boost(true)
                .similarity_boost(0.7)
                .speed(0.97),
        )
        .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)?;

    Ok(())
}

Running Examples

# Set your API key
export ELEVENLABS_API_KEY=your_api_key_here

# Run the basic example
cargo run --example basic_vc

# Run the advanced example
cargo run --example advanced_vc

API Overview

Method Description
ElevenLabsVCClient::new(Vec<u8>, String) Create client instance, requires audio (Vec) & voice_id (String), (required)*
.output_format(String) Output format of the changed voice audio (optional)
.model_id(String) Identifier of the model that will be used (optional)
.voice_settings(VoiceSettings) Voice settings overriding stored settings for the given voice (optional)
.seed(u32) Our system will make a best effort to sample deterministically (optional)
.remove_background_noise(bool) Remove the background noise from your audio input (optional)
.file_format(String) The format of input audio (optional)
.execute() Run request → change audio voice (required)*

Error Handling

The crate uses standard Rust error handling patterns. All async methods return Result types:

match client.voice_changer(audio, voice_id).execute().await {
    Ok(output) => println!("Audio changed voice: {}", output.len()),
    Err(e) => eprintln!("VC request failed: {}", e),
}

Requirements

  • Rust 1.70+ (for async/await support)
  • Tokio runtime
  • Valid ElevenLabs API key

License

Licensed under either of:

at your option.

Contributing

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.

Support

If you like this project, consider supporting me on Patreon 💖

Patreon

Changelog

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.

Commit count: 5

cargo fmt