Skip to main content

Crate elevenlabs_rs

Crate elevenlabs_rs 

Source
Expand description

An unofficial lib crate for ElevenLabs.

ElevenLabs’ website

ElevenLabs’ API reference

§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§

endpoints
error
multipart
multipart/form-data
utils

Macros§

pin_mut
Pins a value on the stack.

Structs§

ApiResponse
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
ElevenLabsClient
Method
The Request Method (VERB)
RawRequestBuilder
VoiceSettings
Voice settings
WebSocketOptions
Runtime settings for ElevenLabs WebSocket sessions.
WebSocketSession
A live ElevenLabs WebSocket session.
WebSocketSessionReport
Completion report for the reader and writer tasks owned by a session.

Enums§

DefaultVoice
FilePart
Source for a multipart file field.
Language
Language
LegacyVoice
Model
OutputFormat
See Elevenlabs documentation on supported output formats.
WebSocketTaskStatus
Completion status for one background WebSocket task.

Traits§

StreamExt
An extension trait for Streams that provides a variety of convenient combinator functions.

Type Aliases§

Result