The official C/C++ library for the Typecast API . Convert text to lifelike speech using AI-powered voices.
Compatible with C11 and later versions. Works with CMake, manual compilation, and supports cross-platform development including Windows, Linux, macOS, and embedded systems.
Source Code Typecast C SDK Source Code
API Documentation Typecast API Documentation
Requirements
CMake 3.14+
libcurl (with SSL support)
C11 compatible compiler
Linux (Ubuntu/Debian)
macOS
Windows (MSVC)
sudo apt-get install build-essential cmake libcurl4-openssl-dev
# libcurl is included with Xcode
xcode-select --install
brew install cmake
vcpkg install curl:x64 - windows
Installation
CMake (Recommended)
Manual
FetchContent (CMake)
Clone the repository and build with CMake: git clone https://github.com/neosapience/typecast-sdk.git
cd typecast-sdk/typecast-c
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
Compile directly with GCC or Clang: git clone https://github.com/neosapience/typecast-sdk.git
cd typecast-sdk/typecast-c
# Compile source files
gcc -c src/typecast.c src/cJSON.c -I include -I src -O2
# Create static library
ar rcs libtypecast.a typecast.o cJSON.o
# Or compile your application directly
gcc -o myapp myapp.c src/typecast.c src/cJSON.c \
-I include -I src -lcurl -O2
Add to your CMakeLists.txt: include (FetchContent)
FetchContent_Declare(
typecast
GIT_REPOSITORY https://github.com/neosapience/typecast-sdk.git
SOURCE_SUBDIR typecast-c
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(typecast)
target_link_libraries (your_target PRIVATE typecast)
Build Options
Option Default Description TYPECAST_BUILD_SHAREDON Build shared library (.dll/.so/.dylib) TYPECAST_BUILD_STATICOFF Build static library TYPECAST_BUILD_EXAMPLESON Build example programs TYPECAST_BUILD_TESTSON Build test programs
Quick Start
#include "typecast.h"
#include <stdio.h>
int main () {
// Initialize client
TypecastClient * client = typecast_client_create ( "YOUR_API_KEY" );
if ( ! client) return 1 ;
// Convert text to speech
TypecastTTSRequest request = { 0 };
request . text = "Hello there! I'm your friendly text-to-speech agent." ;
request . voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
request . model = TYPECAST_MODEL_SSFM_V30;
request . language = "eng" ;
TypecastTTSResponse * response = typecast_text_to_speech (client, & request);
if (response) {
// Save audio file
FILE * fp = fopen ( "output.wav" , "wb" );
fwrite ( response -> audio_data , 1 , response -> audio_size , fp);
fclose (fp);
printf ( "Audio saved! Duration: %.2f s, Size: %zu bytes \n " ,
response -> duration , response -> audio_size );
typecast_tts_response_free (response);
}
// Clean up
typecast_client_destroy (client);
return 0 ;
}
Features
The Typecast C/C++ SDK provides powerful features for text-to-speech conversion:
C and C++ Support : Pure C API with optional C++ wrapper for convenience
Multiple Voice Models : Support for ssfm-v30 (latest) and ssfm-v21 AI 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
Cross-Platform : Windows, Linux, macOS, ARM (32/64-bit) support
Embedded Ready : Optimized for minimal footprint, cross-compilation support
Unreal Engine Ready : Designed for easy integration with game engines
Configuration
Set your API key via environment variable or constructor:
#include <stdlib.h>
// Using environment variable
// export TYPECAST_API_KEY="your-api-key-here"
const char * api_key = getenv ( "TYPECAST_API_KEY" );
TypecastClient * client = typecast_client_create (api_key);
// Or pass directly
TypecastClient * client = typecast_client_create ( "your-api-key-here" );
// Or with custom base URL
TypecastClient * client = typecast_client_create_with_host (
"your-api-key-here" ,
"https://custom-api.example.com"
);
Advanced Usage
Emotion Control (ssfm-v30)
ssfm-v30 offers two emotion control modes: Preset and Smart .
Let the AI infer emotion from context: TypecastTTSRequest request = { 0 };
request.text = "Everything is going to be okay." ;
request.voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
request.model = TYPECAST_MODEL_SSFM_V30;
request.language = "eng" ;
// Smart emotion with context
TypecastPrompt prompt = { 0 };
prompt.emotion_type = TYPECAST_EMOTION_TYPE_SMART;
prompt.previous_text = "I just got the best news!" ; // Optional context
prompt.next_text = "I can't wait to celebrate!" ; // Optional context
request.prompt = & prompt;
TypecastTTSResponse * response = typecast_text_to_speech (client, & request );
Explicitly set emotion with preset values: TypecastTTSRequest request = { 0 };
request.text = "I am so excited to show you these features!" ;
request.voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
request.model = TYPECAST_MODEL_SSFM_V30;
request.language = "eng" ;
// Preset emotion
TypecastPrompt prompt = TYPECAST_PROMPT_DEFAULT ();
prompt.emotion_type = TYPECAST_EMOTION_TYPE_PRESET;
prompt.emotion_preset = TYPECAST_EMOTION_HAPPY; // normal, happy, sad, angry, whisper, toneup, tonedown
prompt.emotion_intensity = 1.5 f ; // Range: 0.0 to 2.0
request.prompt = & prompt;
TypecastTTSResponse * response = typecast_text_to_speech (client, & request );
Audio Customization
Control loudness, pitch, tempo, and output format:
TypecastTTSRequest request = { 0 };
request.text = "Customized audio output!" ;
request.voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
request.model = TYPECAST_MODEL_SSFM_V30;
request.language = "eng" ;
// Configure output settings
TypecastOutput output = TYPECAST_OUTPUT_DEFAULT ();
output.use_target_lufs = 1 ;
output.target_lufs = - 14.0 f ; // Range: -70 to 0 (LUFS)
output.audio_pitch = 2 ; // Range: -12 to +12 semitones
output.audio_tempo = 1.2 f ; // Range: 0.5x to 2.0x
output.audio_format = TYPECAST_AUDIO_FORMAT_MP3; // Options: WAV, MP3
request.output = & output;
request.seed = 42 ; // For reproducible results
TypecastTTSResponse * response = typecast_text_to_speech (client, & request );
if (response) {
const char * ext = ( response -> format == TYPECAST_AUDIO_FORMAT_MP3) ? "mp3" : "wav" ;
char filename [ 64 ];
snprintf (filename, sizeof (filename), "output. %s " , ext);
FILE * fp = fopen (filename, "wb" );
fwrite ( response -> audio_data , 1 , response -> audio_size , fp);
fclose (fp);
printf ( "Duration: %.2f s, Format: %s \n " , response -> duration , ext);
typecast_tts_response_free (response);
}
Voice Discovery (V2 API)
List and filter available voices with enhanced metadata:
// Get all voices
TypecastVoicesResponse * voices = typecast_get_voices (client, NULL );
// Or filter by criteria
TypecastModel model = TYPECAST_MODEL_SSFM_V30;
TypecastGender gender = TYPECAST_GENDER_FEMALE;
TypecastAge age = TYPECAST_AGE_YOUNG_ADULT;
TypecastVoicesFilter filter = { 0 };
filter.model = & model;
filter.gender = & gender;
filter.age = & age;
TypecastVoicesResponse * filtered = typecast_get_voices (client, & filter );
// Display voice info
if (voices) {
for ( size_t i = 0 ; i < voices -> count ; i ++ ) {
TypecastVoice * v = & voices -> voices [i];
printf ( "ID: %s , Name: %s \n " , v -> voice_id , v -> voice_name );
printf ( "Gender: %d , Age: %d \n " , v -> gender , v -> age );
for ( size_t j = 0 ; j < v -> models_count ; j ++ ) {
printf ( "Model: %s , Emotions: " ,
typecast_model_to_string ( v -> models [j]. version ));
for ( size_t k = 0 ; k < v -> models [j]. emotions_count ; k ++ ) {
printf ( " %s " , v -> models [j]. emotions [k]);
}
printf ( " \n " );
}
if ( v -> use_cases ) {
printf ( "Use cases: " );
for ( size_t k = 0 ; k < v -> use_cases_count ; k ++ ) {
printf ( " %s " , v -> use_cases [k]);
}
printf ( " \n " );
}
}
typecast_voices_response_free (voices);
}
Multilingual Content
The SDK supports 37 languages with automatic language detection:
// Auto-detect language (recommended - omit language field)
TypecastTTSRequest request = { 0 };
request.text = "こんにちは。お元気ですか。" ;
request.voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
request.model = TYPECAST_MODEL_SSFM_V30;
// language is NULL, so it will be auto-detected
TypecastTTSResponse * response = typecast_text_to_speech (client, & request );
// Or specify language explicitly using ISO 639-3 code
TypecastTTSRequest korean_request = { 0 };
korean_request.text = "안녕하세요. 반갑습니다." ;
korean_request.voice_id = "tc_672c5f5ce59fac2a48faeaee" ;
korean_request.model = TYPECAST_MODEL_SSFM_V30;
korean_request.language = "kor" ; // ISO 639-3 language code
TypecastTTSResponse * korean_response = typecast_text_to_speech (client, & korean_request );
Supported Languages
The SDK supports 37 languages with automatic language detection:
Code Language Code Language Code Language engEnglish jpnJapanese ukrUkrainian korKorean ellGreek indIndonesian spaSpanish tamTamil danDanish deuGerman tglTagalog sweSwedish fraFrench finFinnish msaMalay itaItalian zhoChinese cesCzech polPolish slkSlovak porPortuguese nldDutch araArabic bulBulgarian rusRussian hrvCroatian ronRomanian benBengali hinHindi hunHungarian nanHokkien norNorwegian panPunjabi thaThai turTurkish vieVietnamese yueCantonese
If not specified, the language will be automatically detected from the input text.
Error Handling
The SDK provides specific error codes for handling API errors:
#include "typecast.h"
TypecastTTSResponse * response = typecast_text_to_speech (client, & request );
if ( ! response) {
const TypecastError * err = typecast_client_get_error (client);
switch ( err -> code ) {
case TYPECAST_ERROR_UNAUTHORIZED:
// 401: Invalid API key
fprintf (stderr, "Invalid API key: %s \n " , err -> message );
break ;
case TYPECAST_ERROR_PAYMENT_REQUIRED:
// 402: Insufficient credits
fprintf (stderr, "Insufficient credits: %s \n " , err -> message );
break ;
case TYPECAST_ERROR_NOT_FOUND:
// 404: Resource not found
fprintf (stderr, "Voice not found: %s \n " , err -> message );
break ;
case TYPECAST_ERROR_UNPROCESSABLE_ENTITY:
// 422: Validation error
fprintf (stderr, "Validation error: %s \n " , err -> message );
break ;
case TYPECAST_ERROR_RATE_LIMIT:
// 429: Rate limit exceeded
fprintf (stderr, "Rate limit exceeded - please retry later \n " );
break ;
case TYPECAST_ERROR_INTERNAL_SERVER:
// 500: Server error
fprintf (stderr, "Server error: %s \n " , err -> message );
break ;
default :
fprintf (stderr, "API error ( %d ): %s \n " , err -> code , err -> message );
break ;
}
}
Error Codes
Error Code Value Description TYPECAST_OK0 Success TYPECAST_ERROR_INVALID_PARAM-1 Invalid request parameters TYPECAST_ERROR_OUT_OF_MEMORY-2 Memory allocation failed TYPECAST_ERROR_CURL_INIT-3 Failed to initialize libcurl TYPECAST_ERROR_NETWORK-4 Network error TYPECAST_ERROR_JSON_PARSE-5 JSON parsing error TYPECAST_ERROR_BAD_REQUEST400 Invalid request TYPECAST_ERROR_UNAUTHORIZED401 Invalid or missing API key TYPECAST_ERROR_PAYMENT_REQUIRED402 Insufficient credits TYPECAST_ERROR_NOT_FOUND404 Resource not found TYPECAST_ERROR_UNPROCESSABLE_ENTITY422 Validation error TYPECAST_ERROR_RATE_LIMIT429 Rate limit exceeded TYPECAST_ERROR_INTERNAL_SERVER500 Server error
C++ Wrapper
For C++ projects, enable the optional C++ wrapper for a more idiomatic interface:
#define TYPECAST_CPP_WRAPPER
#include "typecast.h"
#include <fstream>
#include <iostream>
int main () {
try {
// Initialize client
typecast ::Client client ( "YOUR_API_KEY" );
// Convert text to speech
typecast ::TTSRequest request;
request . text = "Hello there! I'm your friendly text-to-speech agent." ;
request . voiceId = "tc_672c5f5ce59fac2a48faeaee" ;
request . model = typecast :: Model ::SSFM_V30;
request . language = "eng" ;
auto response = client . textToSpeech (request);
// Save audio file
std ::ofstream file ( "output.wav" , std :: ios ::binary);
file . write ( reinterpret_cast < const char *> ( response . audioData . data ()),
response . audioData . size ());
std ::cout << "Audio saved! Duration: " << response . duration << "s \n " ;
} catch ( const typecast ::TypecastException & e) {
std ::cerr << "Error (" << e . code << "): " << e . what () << " \n " ;
return 1 ;
}
return 0 ;
}
The SDK has been verified through automated E2E testing on the following platforms:
Platform Architecture glibc C Standard Status CentOS 6.9 x86_64 2.12 C99 Verified CentOS 7 x86_64 2.17 C11 Verified Amazon Linux 2 x86_64 2.26 C11 Verified Ubuntu 20.04 LTS x86_64 2.31 C11 Verified Debian Bullseye x86_64 2.31 C11 Verified Windows x64 N/A C11 Verified macOS x86_64 / arm64 N/A C11 Verified
Embedded Systems
This SDK can be integrated into embedded systems with network connectivity.
Cross-Compilation
ARM Linux (32-bit)
ARM64 Linux
mkdir build-arm && cd build-arm
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=../cmake/arm-linux-gnueabihf.cmake \
-DTYPECAST_BUILD_STATIC=ON \
-DTYPECAST_BUILD_SHARED=OFF \
-DCMAKE_BUILD_TYPE=MinSizeRel
cmake --build .
mkdir build-arm64 && cd build-arm64
cmake .. \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DTYPECAST_BUILD_STATIC=ON \
-DTYPECAST_BUILD_SHARED=OFF \
-DCMAKE_BUILD_TYPE=MinSizeRel
cmake --build .
Memory Requirements
Component Approximate Size Static library (MinSizeRel) ~50 KB Runtime heap per client ~8 KB TTS response buffer Variable (audio size) JSON parsing buffer ~4 KB
Unreal Engine Integration
This SDK is designed for seamless integration with Unreal Engine 4.27+ and Unreal Engine 5.x.
Build the SDK
Build as a static library: mkdir build && cd build
cmake .. -DTYPECAST_BUILD_STATIC=ON -DTYPECAST_BUILD_SHARED=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
Create Plugin Structure
Create a plugin in your Unreal project: Plugins/
└── TypecastTTS/
├── Source/TypecastTTS/
│ ├── Private/
│ ├── Public/
│ └── ThirdParty/Typecast/
│ ├── include/typecast.h
│ └── lib/Win64/typecast_static.lib
├── TypecastTTS.uplugin
└── TypecastTTS.Build.cs
Configure Build.cs
Add library linking to your Build.cs: // Add include path
PublicIncludePaths . Add ( Path . Combine ( ThirdPartyPath , "include" ));
PublicDefinitions . Add ( "TYPECAST_STATIC" );
// Link static library (platform-specific)
if ( Target . Platform == UnrealTargetPlatform . Win64 )
{
PublicAdditionalLibraries . Add (
Path . Combine ( LibPath , "Win64" , "typecast_static.lib" ));
AddEngineThirdPartyPrivateStaticDependencies ( Target , "libcurl" );
}
For complete Unreal Engine integration guide including Blueprint support and audio playback, see the README in the SDK repository.
API Reference
Client Functions
Function Description typecast_client_create(api_key)Create client with API key typecast_client_create_with_host(api_key, host)Create client with custom host typecast_client_destroy(client)Destroy client and free resources typecast_client_get_error(client)Get last error information
Text-to-Speech Functions
Function Description typecast_text_to_speech(client, request)Convert text to speech audio typecast_tts_response_free(response)Free TTS response memory
Voice Functions
Function Description typecast_get_voices(client, filter)Get available voices (optionally filtered) typecast_get_voice(client, voice_id)Get a specific voice by ID typecast_voices_response_free(response)Free voices response memory typecast_voice_free(voice)Free single voice memory
Utility Functions
Function Description typecast_version()Get library version string typecast_model_to_string(model)Convert model enum to string typecast_emotion_to_string(emotion)Convert emotion enum to string typecast_audio_format_to_string(format)Convert format enum to string typecast_error_message(code)Get error message for error code
TypecastTTSRequest Fields
Field Type Required Description textconst char*✓ Text to synthesize (max 2000 chars) voice_idconst char*✓ Voice ID (format: tc_* or uc_*) modelTypecastModel✓ TTS model (SSFM_V21 or SSFM_V30) languageconst char*ISO 639-3 code (auto-detected if NULL) promptTypecastPrompt*Emotion settings outputTypecastOutput*Audio output settings seedintRandom seed for reproducibility
TypecastTTSResponse Fields
Field Type Description audio_datauint8_t*Generated audio data audio_sizesize_tSize of audio data in bytes durationfloatAudio duration in seconds formatTypecastAudioFormatAudio format (wav or mp3)