elevenlabs-api
A very simple Rust library for Elevenlabs API, free from complex async operations and redundant dependencies. Inspired by openai-api.
API
Check the official API reference.
API | Support |
---|---|
Text to Speech | ✔️ |
Text to Speech Stream | ❌ |
Models | ❌ |
Voices | ❌ |
Samples | ❌ |
History | ❌ |
User | ❌ |
Usage
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 ;
// 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 = from_env.unwrap;
let elevenlabs = new;
// Create the tts body.
let tts_body = TtsBody ;
// Generate the speech for the text by using the voice with id yoZ06aMxZJJ28mfd3POQ.
let tts_result = elevenlabs.tts;
let bytes = tts_result.unwrap;
// Do what you need with the bytes.
// The server responds with "audio/mpeg" so we can save as mp3.
write.unwrap;
Check the examples folder.