Skip to main content

typecast_rust/
lib.rs

1//! Typecast Rust SDK
2//!
3//! Official Rust SDK for the Typecast Text-to-Speech API.
4//!
5//! # Quick Start
6//!
7//! ```no_run
8//! use typecast_rust::{TypecastClient, TTSRequest, TTSModel, ClientConfig};
9//!
10//! #[tokio::main]
11//! async fn main() -> typecast_rust::Result<()> {
12//!     // Create a client from environment variables
13//!     let client = TypecastClient::from_env()?;
14//!
15//!     // Or create with explicit API key
16//!     // let client = TypecastClient::with_api_key("your-api-key")?;
17//!
18//!     // Create a TTS request
19//!     let request = TTSRequest::new(
20//!         "tc_60e5426de8b95f1d3000d7b5",
21//!         "Hello, world!",
22//!         TTSModel::SsfmV30,
23//!     );
24//!
25//!     // Generate speech
26//!     let response = client.text_to_speech(&request).await?;
27//!     
28//!     // Save audio to file
29//!     std::fs::write("output.wav", &response.audio_data)?;
30//!     println!("Audio saved! Duration: {} seconds", response.duration);
31//!
32//!     Ok(())
33//! }
34//! ```
35//!
36//! # Features
37//!
38//! - **Text-to-Speech**: Convert text to natural-sounding speech
39//! - **Multiple Models**: Support for ssfm-v21 and ssfm-v30 models
40//! - **Emotion Control**: Preset emotions and smart context-aware inference
41//! - **Voice Discovery**: List and filter available voices
42//! - **Audio Customization**: Control volume, pitch, tempo, and format
43//!
44//! # Configuration
45//!
46//! The SDK can be configured using environment variables:
47//!
48//! - `TYPECAST_API_KEY`: Your Typecast API key (required)
49//! - `TYPECAST_API_HOST`: Custom API host (optional, defaults to <https://api.typecast.ai>)
50//!
51//! # Error Handling
52//!
53//! All operations return a `Result<T, TypecastError>`. The error type provides
54//! detailed information about what went wrong:
55//!
56//! ```no_run
57//! use typecast_rust::{TypecastClient, TTSRequest, TTSModel, TypecastError};
58//!
59//! # async fn example() -> typecast_rust::Result<()> {
60//! let client = TypecastClient::from_env()?;
61//! let request = TTSRequest::new("invalid_voice", "Hello", TTSModel::SsfmV30);
62//!
63//! match client.text_to_speech(&request).await {
64//!     Ok(response) => println!("Success!"),
65//!     Err(TypecastError::NotFound { detail }) => {
66//!         println!("Voice not found: {}", detail);
67//!     }
68//!     Err(TypecastError::Unauthorized { .. }) => {
69//!         println!("Invalid API key");
70//!     }
71//!     Err(e) => println!("Other error: {}", e),
72//! }
73//! # Ok(())
74//! # }
75//! ```
76
77pub mod client;
78pub mod errors;
79pub mod models;
80
81// Re-export main types for convenience
82pub use client::{ClientConfig, TypecastClient, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_SECS};
83pub use errors::{Result, TypecastError};
84pub use models::{
85    Age, AudioFormat, EmotionPreset, ErrorResponse, Gender, ModelInfo, Output, PresetPrompt,
86    Prompt, SmartPrompt, TTSModel, TTSPrompt, TTSRequest, TTSResponse, UseCase, VoiceV2,
87    VoicesV2Filter,
88};