pub struct TypecastClient { /* private fields */ }Expand description
The main Typecast API client
Implementations§
Source§impl TypecastClient
impl TypecastClient
Sourcepub fn new(config: ClientConfig) -> Result<Self>
pub fn new(config: ClientConfig) -> Result<Self>
Create a new TypecastClient with the given configuration
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new TypecastClient from environment variables
Reads TYPECAST_API_KEY and optionally TYPECAST_API_HOST
Sourcepub fn with_api_key(api_key: impl Into<String>) -> Result<Self>
pub fn with_api_key(api_key: impl Into<String>) -> Result<Self>
Create a new TypecastClient with just an API key
Sourcepub fn api_key_masked(&self) -> String
pub fn api_key_masked(&self) -> String
Get the API key (masked)
Sourcepub async fn text_to_speech(&self, request: &TTSRequest) -> Result<TTSResponse>
pub async fn text_to_speech(&self, request: &TTSRequest) -> Result<TTSResponse>
Convert text to speech
§Arguments
request- The TTS request containing text, voice_id, model, and optional settings
§Returns
Returns a TTSResponse containing the audio data, duration, and format
§Example
use typecast_rust::{TypecastClient, TTSRequest, TTSModel, ClientConfig};
let client = TypecastClient::from_env()?;
let request = TTSRequest::new(
"tc_60e5426de8b95f1d3000d7b5",
"Hello, world!",
TTSModel::SsfmV30,
);
let response = client.text_to_speech(&request).await?;
println!("Audio duration: {} seconds", response.duration);Sourcepub async fn get_voices_v2(
&self,
filter: Option<VoicesV2Filter>,
) -> Result<Vec<VoiceV2>>
pub async fn get_voices_v2( &self, filter: Option<VoicesV2Filter>, ) -> Result<Vec<VoiceV2>>
Get voices with enhanced metadata (V2 API)
§Arguments
filter- Optional filter for voices (model, gender, age, use_cases)
§Returns
Returns a list of VoiceV2 with enhanced metadata
§Example
use typecast_rust::{TypecastClient, VoicesV2Filter, TTSModel, Gender, ClientConfig};
let client = TypecastClient::from_env()?;
// Get all voices
let voices = client.get_voices_v2(None).await?;
// Get filtered voices
let filter = VoicesV2Filter::new()
.model(TTSModel::SsfmV30)
.gender(Gender::Female);
let filtered_voices = client.get_voices_v2(Some(filter)).await?;Sourcepub async fn get_voice_v2(&self, voice_id: &str) -> Result<VoiceV2>
pub async fn get_voice_v2(&self, voice_id: &str) -> Result<VoiceV2>
Get a specific voice by ID with enhanced metadata (V2 API)
§Arguments
voice_id- The voice ID (e.g., ‘tc_60e5426de8b95f1d3000d7b5’)
§Returns
Returns a VoiceV2 with enhanced metadata
§Example
use typecast_rust::{TypecastClient, ClientConfig};
let client = TypecastClient::from_env()?;
let voice = client.get_voice_v2("tc_60e5426de8b95f1d3000d7b5").await?;
println!("Voice: {} ({})", voice.voice_name, voice.voice_id);Trait Implementations§
Source§impl Clone for TypecastClient
impl Clone for TypecastClient
Source§fn clone(&self) -> TypecastClient
fn clone(&self) -> TypecastClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TypecastClient
impl !RefUnwindSafe for TypecastClient
impl Send for TypecastClient
impl Sync for TypecastClient
impl Unpin for TypecastClient
impl UnsafeUnpin for TypecastClient
impl !UnwindSafe for TypecastClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more