Expand description
An unofficial lib crate for ElevenLabs.
§Example
§Text to Speech
use elevenlabs_rs::{ElevenLabsClient, Result, DefaultVoice, Model};
use elevenlabs_rs::endpoints::genai::tts::{TextToSpeech, TextToSpeechBody};
use elevenlabs_rs::utils::play;
#[tokio::main]
async fn main() -> Result<()> {
let client = ElevenLabsClient::from_env()?;
let txt = "Hello! 你好! Hola! नमस्ते! Bonjour! \
こんにちは! مرحبا! 안녕하세요! Ciao! Cześć! Привіт! வணக்கம்!";
let body = TextToSpeechBody::new(txt)
.with_model_id(Model::ElevenMultilingualV2);
let endpoint = TextToSpeech::new(DefaultVoice::Brian, body);
let speech = client.hit(endpoint).await?;
play(speech)?;
Ok(())
}§WebSocket lifecycle
WebSocket entry points such as
ElevenLabsClient::connect_text_to_speech,
ElevenLabsClient::connect_multi_context_text_to_speech, and
ElevenLabsClient::connect_realtime_speech_to_text return a
WebSocketSession when the ws and genai features are enabled. The
session implements Stream for inbound server messages and owns background
reader/writer tasks.
Prefer calling WebSocketSession::close when the session has completed so
the client sends a close frame before shutting down background work. Dropping
the session is still safe and aborts background tasks as a fallback. For
diagnostics after a stream ends, or after close/abort, call
WebSocketSession::join to inspect reader and writer task completion.
Use WebSocketOptions with the connect_*_with_options methods to tune
inbound buffering and the graceful-close timeout.
Modules§
Macros§
- pin_mut
- Pins a value on the stack.
Structs§
- ApiResponse
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Eleven
Labs Client - Method
- The Request Method (VERB)
- RawRequest
Builder - Voice
Settings - Voice settings
- WebSocket
Options - Runtime settings for ElevenLabs WebSocket sessions.
- WebSocket
Session - A live ElevenLabs WebSocket session.
- WebSocket
Session Report - Completion report for the reader and writer tasks owned by a session.
Enums§
- Default
Voice - File
Part - Source for a multipart file field.
- Language
- Language
- Legacy
Voice - Model
- Output
Format - See Elevenlabs documentation on supported output formats.
- WebSocket
Task Status - Completion status for one background WebSocket task.
Traits§
- Stream
Ext - An extension trait for
Streams that provides a variety of convenient combinator functions.