elevenlabs_sdk/lib.rs
1//! # ElevenLabs Rust SDK
2//!
3//! A comprehensive, async Rust SDK for the [ElevenLabs](https://elevenlabs.io) API,
4//! providing text-to-speech, voice management, audio isolation, speech-to-text,
5//! and other audio AI capabilities.
6//!
7//! ## Quick Start
8//!
9//! ```no_run
10//! use elevenlabs_sdk::{ClientConfig, ElevenLabsClient, types::TextToSpeechRequest};
11//!
12//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
13//! // Create client from environment variable ELEVENLABS_API_KEY
14//! let config = ClientConfig::from_env()?;
15//! let client = ElevenLabsClient::new(config)?;
16//!
17//! // Text-to-speech
18//! let request = TextToSpeechRequest::new("Hello from Rust!");
19//! let audio_bytes = client.text_to_speech().convert("voice_id", &request, None, None).await?;
20//! println!("Received {} bytes of audio", audio_bytes.len());
21//!
22//! // List available voices
23//! let voices = client.voices().list(None).await?;
24//! for voice in &voices.voices {
25//! println!(" {} ({})", voice.name, voice.voice_id);
26//! }
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! ## Features
32//!
33//! - **Text-to-Speech** — Convert text to natural-sounding speech with full and streaming
34//! endpoints, including character-level timestamp alignment.
35//! - **Voice Management** — List, create, edit, and delete voices; manage voice settings and
36//! samples.
37//! - **WebSocket Streaming** — Real-time TTS via input-streaming WebSocket, and conversational AI
38//! with bidirectional audio/text.
39//! - **Audio Isolation** — Remove background noise from audio files.
40//! - **Speech-to-Text** — Transcribe audio to text.
41//! - **Speech-to-Speech** — Convert speech with a different voice.
42//! - **Sound Generation** — Generate sound effects from text prompts.
43//! - **Models** — Query available synthesis models.
44//! - **User & Workspace** — Account and workspace management.
45//! - **Retry & Error Handling** — Automatic retry with exponential backoff, structured error types
46//! with status codes and rate-limit info.
47//!
48//! ## Module Organization
49//!
50//! | Module | Description |
51//! |--------|-------------|
52//! | [`auth`] | API key authentication and secure key handling |
53//! | [`config`] | Client configuration builder with env-var support |
54//! | [`error`] | Error types ([`ElevenLabsError`]) and `Result` alias |
55//! | [`client`] | HTTP client ([`ElevenLabsClient`]) with automatic auth |
56//! | [`types`] | Shared request/response types mirroring the OpenAPI spec |
57//! | [`services`] | Typed endpoint wrappers (TTS, voices, models, etc.) |
58//! | [`ws`] | WebSocket streaming (TTS input-streaming, conversational AI) |
59
60pub mod auth;
61pub mod client;
62pub mod config;
63pub mod error;
64mod middleware;
65pub mod services;
66pub mod types;
67pub mod ws;
68
69pub use auth::ApiKey;
70pub use client::ElevenLabsClient;
71pub use config::{ClientConfig, ClientConfigBuilder, ConfigError};
72pub use error::{ElevenLabsError, Result};
73pub use services::{
74 AgentsService, AudioIsolationService, AudioNativeService, ForcedAlignmentService,
75 HistoryService, ModelsService, MusicService, PvcVoicesService, SingleUseTokenService,
76 SoundGenerationService, SpeechToSpeechService, SpeechToTextService, StudioService,
77 TextToDialogueService, TextToSpeechService, TextToVoiceService, UserService,
78 VoiceGenerationService, VoicesService, WorkspaceService,
79};
80pub use ws::{
81 conversation::{ConversationEvent, ConversationWebSocket},
82 tts::{TtsWebSocket, TtsWsConfig, TtsWsResponse},
83};