Packagist
Typecast PHP SDK
Source Code
Typecast PHP SDK Source Code
Installation
Install via Composer:Quick Start
Features
- Multiple Voice Models: Support for
ssfm-v30(latest) andssfm-v21AI voice models - Multi-language Support: 37 languages including English, Korean, Spanish, Japanese, Chinese, and more
- Emotion Control: Preset emotions (normal, happy, sad, angry, whisper, toneup, tonedown) or smart context-aware inference
- Audio Customization: Control loudness (LUFS -70 to 0), pitch (-12 to +12 semitones), tempo (0.5x to 2.0x), and format (WAV/MP3)
- Voice Discovery: V2 Voices API with filtering by model, gender, age, and use cases
- Streaming: Real-time chunked audio delivery for low-latency playback via callback
- Guzzle 7: Industry-standard HTTP client with automatic retries and connection pooling
- Type Safety: Typed properties and named arguments (PHP 8.1+)
Configuration
Set your API key via environment variable or pass directly:Advanced Usage
Emotion Control (ssfm-v30)
ssfm-v30 offers two emotion control modes: Preset and Smart.- Smart Mode
- Preset Mode
Let the AI infer emotion from context:
Audio Customization
Control loudness, pitch, tempo, and output format:Voice Discovery (V2 API)
List and filter available voices with enhanced metadata:Streaming
Stream audio chunks in real-time for low-latency playback via callback:WAV streaming format: 32000 Hz, 16-bit, mono PCM. The first chunk includes a 44-byte WAV header (size =
0xFFFFFFFF); subsequent chunks are raw PCM only. For MP3: 320 kbps, 44100 Hz, each chunk is independently decodable. The streaming endpoint does not support volume or target_lufs.Supported Languages
The SDK supports 37 languages with automatic language detection:| Code | Language | Code | Language | Code | Language |
|---|---|---|---|---|---|
eng | English | jpn | Japanese | ukr | Ukrainian |
kor | Korean | ell | Greek | ind | Indonesian |
spa | Spanish | tam | Tamil | dan | Danish |
deu | German | tgl | Tagalog | swe | Swedish |
fra | French | fin | Finnish | msa | Malay |
ita | Italian | zho | Chinese | ces | Czech |
pol | Polish | slk | Slovak | por | Portuguese |
nld | Dutch | ara | Arabic | bul | Bulgarian |
rus | Russian | hrv | Croatian | ron | Romanian |
ben | Bengali | hin | Hindi | hun | Hungarian |
nan | Hokkien | nor | Norwegian | pan | Punjabi |
tha | Thai | tur | Turkish | vie | Vietnamese |
yue | Cantonese |
If not specified, the language will be automatically detected from the input text.
Error Handling
The SDK throws specific exceptions for each HTTP error:| Exception | Status Code | Description |
|---|---|---|
BadRequestException | 400 | Invalid request parameters |
UnauthorizedException | 401 | Invalid or missing API key |
PaymentRequiredException | 402 | Insufficient credits |
NotFoundException | 404 | Resource not found |
UnprocessableEntityException | 422 | Validation error |
RateLimitException | 429 | Rate limit exceeded |
InternalServerException | 500 | Server error |
API Reference
TypecastClient Methods
| Method | Description |
|---|---|
textToSpeech(TTSRequest) | Convert text to speech audio |
textToSpeechStream(TTSRequestStream, callable) | Stream audio chunks via callback |
getMySubscription() | Get subscription info |
getVoices(?string $model) | Get available voices (V1) |
getVoicesV2(?VoicesV2Filter) | Get voices with metadata (V2) |
getVoiceV2(string $voiceId) | Get a specific voice |