Expand description
§Gradium Rust Client
A Rust client library for the Gradium API, providing text-to-speech (TTS) capabilities via WebSocket connections.
§Quick Start
use gradium::{Client, protocol::tts::Setup, protocol::AudioFormat};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let api_key = gradium::api_key_from_env().expect("GRADIUM_API_KEY not set");
let client = Client::new(&api_key);
let setup = Setup::new("m86j6D7UZpGzHsNu").with_output_format(AudioFormat::Wav);
let result = gradium::tts("Hello, world!", setup, &client).await?;
let filename = "output.wav";
std::fs::write(filename, result.raw_data())?;
println!("Generated {} bytes of audio and saved to {}", result.raw_data().len(), filename);
Ok(())
}§Features
- Simple API: High-level
tts()function for one-shot text-to-speech conversion - Streaming Support:
TtsStreamfor advanced use cases with real-time audio streaming - Multiple Formats: Support for PCM, WAV, and Opus audio formats
- Async/Await: Built on tokio for efficient async I/O
§Environment Configuration
The client expects the GRADIUM_API_KEY environment variable to be set with your API key.
You can retrieve it using the api_key_from_env() function.
Re-exports§
pub use client::Client;pub use stt::SttResult;pub use stt::SttStream;pub use stt::stt;pub use stt::stt_stream;pub use tts::TtsMultiplexStream;pub use tts::TtsResult;pub use tts::TtsStream;pub use tts::tts;pub use tts::tts_stream;
Modules§
- client
- Client module for connecting to the Gradium API.
- protocol
- Protocol definitions for Gradium API communication.
- stt
- Speech-to-text (STT) client functionality.
- tts
- Text-to-speech functionality and streaming support.
Structs§
- Text
With Timestamps - Represents text with associated timing information.
Functions§
- api_
key_ from_ env - Retrieves the Gradium API key from the
GRADIUM_API_KEYenvironment variable. - base_
url_ from_ env - Retrieves the Gradium base URL from the
GRADIUM_BASE_URLenvironment variable.