elevenlabs_api/
lib.rs

1#![warn(unused_crate_dependencies)]
2#![forbid(unsafe_code)]
3#![warn(clippy::all)]
4
5//!<div align="center">
6//! <!-- Build -->
7//! <img src="https://img.shields.io/github/actions/workflow/status/alexjercan/elevenlabs-api/rust.yml?style=flat-square"
8//! alt="Github Worflow Status" />
9//! <!-- Version -->
10//! <a href="https://crates.io/crates/elevenlabs-api">
11//!   <img src="https://img.shields.io/crates/v/elevenlabs-api?style=flat-square"
12//!   alt="Crates.io version" />
13//! </a>
14//! <!-- Docs -->
15//! <a href="https://docs.rs/elevenlabs-api">
16//!   <img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
17//!     alt="docs.rs docs" />
18//! </a>
19//! <!-- Downloads -->
20//! <a href="https://crates.io/crates/elevenlabs-api">
21//!   <img src="https://img.shields.io/crates/d/elevenlabs-api?style=flat-square"
22//!     alt="Crates.io downloads" />
23//! </a>
24//! <!-- License -->
25//! <a href="https://github.com/alexjercan/elevenlabs-api/blob/master/LICENSE">
26//!   <img src="https://img.shields.io/github/license/alexjercan/elevenlabs-api?style=flat-square"
27//!     alt="Crates.io downloads" />
28//! </a>
29//!</div>
30//!
31//! A very simple Rust library for Elevenlabs API, free from complex async operations and redundant dependencies. Inspired by [openai-api](https://github.com/openai-rs/openai-api).
32//!
33//! ## API
34//!
35//! Check the [official](https://docs.elevenlabs.io/api-reference/quick-start/introduction) API reference.
36//!
37//! |API|Support|
38//! |---|---|
39//! |Text to Speech|✔️|
40//! |Text to Speech Stream|❌|
41//! |Models|❌|
42//! |Voices|❌|
43//! |Samples|❌|
44//! |History|❌|
45//! |User|❌|
46//!
47//! ## Usage
48//!
49//! Install the library using the Cargo.toml file.
50//!
51//! Export your API key into the environment variables
52//!
53//! ```console
54//! export ELEVENLABS_API_KEY=...
55//! ```
56//!
57//! Then use the crate in your Rust code:
58//!
59//! ```no_run
60//! # fn main() {
61//!   // import the dependencies
62//!   use elevenlabs_api::{
63//!       tts::{TtsApi, TtsBody},
64//!       *,
65//!   };
66//!
67//!   // Load API key from environment ELEVENLABS_API_KEY.
68//!   // You can also hadcode through `Auth::new(<your_api_key>)`, but it is not recommended.
69//!   let auth = Auth::from_env().unwrap();
70//!   let elevenlabs = Elevenlabs::new(auth, "https://api.elevenlabs.io/v1/");
71//!
72//!   // Create the tts body.
73//!   let tts_body = TtsBody {
74//!       model_id: None,
75//!       text: "Hello world".to_string(),
76//!       voice_settings: None,
77//!   };
78//!
79//!   // Generate the speech for the text by using the voice with id yoZ06aMxZJJ28mfd3POQ.
80//!   let tts_result = elevenlabs.tts(&tts_body, "yoZ06aMxZJJ28mfd3POQ");
81//!   let bytes = tts_result.unwrap();
82//!
83//!   // Do what you need with the bytes.
84//!   // The server responds with "audio/mpeg" so we can save as mp3.
85//!   std::fs::write("tts.mp3", bytes).unwrap();
86//! # }
87//! ```
88//!
89
90pub mod apis;
91pub use apis::*;
92
93pub mod elevenlabs;
94pub use elevenlabs::*;