Crates.io | elevenlabs-api |
lib.rs | elevenlabs-api |
version | 0.1.1 |
source | src |
created_at | 2023-07-06 18:15:44.912377 |
updated_at | 2023-07-06 19:17:48.582272 |
description | A very simple Rust library for Elevenlabs API, free from complex async operations and redundant dependencies. |
homepage | https://github.com/alexjercan/elevenlabs-api |
repository | |
max_upload_size | |
id | 910170 |
size | 27,582 |
A very simple Rust library for Elevenlabs API, free from complex async operations and redundant dependencies. Inspired by openai-api.
Check the official API reference.
API | Support |
---|---|
Text to Speech | ✔️ |
Text to Speech Stream | ❌ |
Models | ❌ |
Voices | ❌ |
Samples | ❌ |
History | ❌ |
User | ❌ |
Install the library using the Cargo.toml file.
Export your API key into the environment variables
export ELEVENLABS_API_KEY=...
Then use the crate in your Rust code:
// import the dependencies
use elevenlabs_api::{
tts::{TtsApi, TtsBody},
*,
};
// Load API key from environment ELEVENLABS_API_KEY.
// You can also hadcode through `Auth::new(<your_api_key>)`, but it is not recommended.
let auth = Auth::from_env().unwrap();
let elevenlabs = Elevenlabs::new(auth, "https://api.elevenlabs.io/v1/");
// Create the tts body.
let tts_body = TtsBody {
model_id: None,
text: "Hello world".to_string(),
voice_settings: None,
};
// Generate the speech for the text by using the voice with id yoZ06aMxZJJ28mfd3POQ.
let tts_result = elevenlabs.tts(&tts_body, "yoZ06aMxZJJ28mfd3POQ");
let bytes = tts_result.unwrap();
// Do what you need with the bytes.
// The server responds with "audio/mpeg" so we can save as mp3.
std::fs::write("tts.mp3", bytes).unwrap();
Check the examples folder.