Typecast Rust SDK
Official Rust SDK for the Typecast Text-to-Speech API.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
use ;
async
Configuration
Environment Variables
TYPECAST_API_KEY: Your Typecast API key (required)TYPECAST_API_HOST: Custom API host (optional, defaults tohttps://api.typecast.ai)
Custom Configuration
use ;
use Duration;
let config = new
.base_url
.timeout;
let client = new?;
Features
Text-to-Speech
use ;
// Basic request
let request = new;
// With language and output settings
let request = new
.language
.output
.seed;
Emotion Control
Preset Emotions (ssfm-v30)
use ;
let request = new
.prompt;
Available presets:
Normal- Neutral, balanced toneHappy- Bright, cheerful expressionSad- Melancholic, subdued toneAngry- Strong, intense deliveryWhisper- Soft, quiet speech (ssfm-v30 only)ToneUp- Higher tonal emphasis (ssfm-v30 only)ToneDown- Lower tonal emphasis (ssfm-v30 only)
Smart Context-Aware Emotion (ssfm-v30)
use SmartPrompt;
let request = new
.prompt;
Voice Discovery
use ;
// Get all voices
let voices = client.get_voices_v2.await?;
// Filter voices
let filter = new
.model
.gender
.age;
let voices = client.get_voices_v2.await?;
// Get specific voice
let voice = client.get_voice_v2.await?;
println!;
Error Handling
use TypecastError;
match client.text_to_speech.await
Supported Languages
The API supports 37 languages with ssfm-v30 model:
| Code | Language | Code | Language | Code | Language |
|---|---|---|---|---|---|
| eng | English | kor | Korean | jpn | Japanese |
| zho | Chinese | spa | Spanish | fra | French |
| deu | German | ita | Italian | por | Portuguese |
| rus | Russian | ara | Arabic | hin | Hindi |
| ... and more |
Timestamp TTS
Generate speech with word- and/or character-level alignment data, then convert it to SRT or WebVTT subtitles with a single method call.
use ;
use TTSRequestWithTimestamps;
async
Captioning rules
- Word segments are used when two or more words are present; character segments are used otherwise (useful for languages without whitespace such as Japanese or Chinese).
- A cue is flushed when: a sentence-terminating punctuation mark is encountered
(
. ? ! 。 ? !), the cue duration would exceed 7 seconds, or the cue text would exceed 42 Unicode codepoints.
Running Tests
# Set your API key
# Run all tests (unit + timestamp + doc tests)
# Run timestamp tests only
# Run integration tests only (requires TYPECAST_API_KEY)
License
MIT License - see LICENSE for details.