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//! .map_err(|e| typecast_rust::TypecastError::IoError(e.to_string()))?;
31//! println!("Audio saved! Duration: {} seconds", response.duration);
32//!
33//! Ok(())
34//! }
35//! ```
36//!
37//! # Features
38//!
39//! - **Text-to-Speech**: Convert text to natural-sounding speech
40//! - **Multiple Models**: Support for ssfm-v21 and ssfm-v30 models
41//! - **Emotion Control**: Preset emotions and smart context-aware inference
42//! - **Voice Discovery**: List and filter available voices
43//! - **Audio Customization**: Control volume, pitch, tempo, and format
44//!
45//! # Configuration
46//!
47//! The SDK can be configured using environment variables:
48//!
49//! - `TYPECAST_API_KEY`: Your Typecast API key (required)
50//! - `TYPECAST_API_HOST`: Custom API host (optional, defaults to <https://api.typecast.ai>)
51//!
52//! # Error Handling
53//!
54//! All operations return a `Result<T, TypecastError>`. The error type provides
55//! detailed information about what went wrong:
56//!
57//! ```no_run
58//! use typecast_rust::{TypecastClient, TTSRequest, TTSModel, TypecastError};
59//!
60//! # async fn example() -> typecast_rust::Result<()> {
61//! let client = TypecastClient::from_env()?;
62//! let request = TTSRequest::new("invalid_voice", "Hello", TTSModel::SsfmV30);
63//!
64//! match client.text_to_speech(&request).await {
65//! Ok(response) => println!("Success!"),
66//! Err(TypecastError::NotFound { detail }) => {
67//! println!("Voice not found: {}", detail);
68//! }
69//! Err(TypecastError::Unauthorized { .. }) => {
70//! println!("Invalid API key");
71//! }
72//! Err(e) => println!("Other error: {}", e),
73//! }
74//! # Ok(())
75//! # }
76//! ```
77
78pub mod client;
79pub mod errors;
80pub mod models;
81pub mod timestamps;
82
83// Re-export main types for convenience
84pub use client::{ClientConfig, TypecastClient, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_SECS};
85pub use errors::{Result, TypecastError};
86pub use models::{
87 Age, AudioFormat, Credits, EmotionPreset, ErrorResponse, Gender, Limits, ModelInfo, Output,
88 OutputStream, PlanTier, PresetPrompt, Prompt, SmartPrompt, SubscriptionResponse, TTSModel,
89 TTSPrompt, TTSRequest, TTSRequestStream, TTSResponse, UseCase, VoiceV2, VoicesV2Filter,
90};
91pub use timestamps::{
92 AlignmentSegmentCharacter, AlignmentSegmentWord, TTSRequestWithTimestamps,
93 TTSWithTimestampsResponse,
94};