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 text_to_speech_stream(
&self,
request: &TTSRequestStream,
) -> Result<AudioByteStream>
pub async fn text_to_speech_stream( &self, request: &TTSRequestStream, ) -> Result<AudioByteStream>
Convert text to speech as a streaming response
Returns a stream of audio byte chunks. For wav output the first chunk
contains the WAV header followed by PCM samples; for mp3 output each
chunk is independently decodable.
§Arguments
request- The streaming TTS request
§Returns
A pinned boxed Stream yielding Result<Bytes> chunks.
§Example
use futures_util::StreamExt;
use typecast_rust::{TypecastClient, TTSRequestStream, TTSModel};
let client = TypecastClient::from_env()?;
let request = TTSRequestStream::new(
"tc_60e5426de8b95f1d3000d7b5",
"Hello, world!",
TTSModel::SsfmV30,
);
let mut stream = client.text_to_speech_stream(&request).await?;
while let Some(chunk) = stream.next().await {
let bytes = chunk?;
// write bytes to file or audio sink
let _ = bytes;
}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);Sourcepub async fn get_my_subscription(&self) -> Result<SubscriptionResponse>
pub async fn get_my_subscription(&self) -> Result<SubscriptionResponse>
Get the authenticated user’s subscription
§Returns
Returns a SubscriptionResponse containing the user’s plan, credits,
and usage limits.
§Example
use typecast_rust::TypecastClient;
let client = TypecastClient::from_env()?;
let subscription = client.get_my_subscription().await?;
println!("Plan: {:?}", subscription.plan);
println!(
"Credits: {}/{}",
subscription.credits.used_credits, subscription.credits.plan_credits
);Trait Implementations§
Source§impl Clone for TypecastClient
impl Clone for TypecastClient
Source§fn clone(&self) -> TypecastClient
fn clone(&self) -> TypecastClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more