Skip to main content
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
sudo apt-get install build-essential cmake libcurl4-openssl-dev

Installation

Build Options

OptionDefaultDescription
TYPECAST_BUILD_SHAREDONBuild shared library (.dll/.so/.dylib)
TYPECAST_BUILD_STATICOFFBuild static library
TYPECAST_BUILD_EXAMPLESONBuild example programs
TYPECAST_BUILD_TESTSONBuild 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: %.2fs, 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);

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.0f;                    // Range: -70 to 0 (LUFS)
output.audio_pitch = 2;                        // Range: -12 to +12 semitones
output.audio_tempo = 1.2f;                     // 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: %.2fs, 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:
CodeLanguageCodeLanguageCodeLanguage
engEnglishjpnJapaneseukrUkrainian
korKoreanellGreekindIndonesian
spaSpanishtamTamildanDanish
deuGermantglTagalogsweSwedish
fraFrenchfinFinnishmsaMalay
itaItalianzhoChinesecesCzech
polPolishslkSlovakporPortuguese
nldDutcharaArabicbulBulgarian
rusRussianhrvCroatianronRomanian
benBengalihinHindihunHungarian
nanHokkiennorNorwegianpanPunjabi
thaThaiturTurkishvieVietnamese
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 CodeValueDescription
TYPECAST_OK0Success
TYPECAST_ERROR_INVALID_PARAM-1Invalid request parameters
TYPECAST_ERROR_OUT_OF_MEMORY-2Memory allocation failed
TYPECAST_ERROR_CURL_INIT-3Failed to initialize libcurl
TYPECAST_ERROR_NETWORK-4Network error
TYPECAST_ERROR_JSON_PARSE-5JSON parsing error
TYPECAST_ERROR_BAD_REQUEST400Invalid request
TYPECAST_ERROR_UNAUTHORIZED401Invalid or missing API key
TYPECAST_ERROR_PAYMENT_REQUIRED402Insufficient credits
TYPECAST_ERROR_NOT_FOUND404Resource not found
TYPECAST_ERROR_UNPROCESSABLE_ENTITY422Validation error
TYPECAST_ERROR_RATE_LIMIT429Rate limit exceeded
TYPECAST_ERROR_INTERNAL_SERVER500Server 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;
}

Platform Support

The SDK has been verified through automated E2E testing on the following platforms:
PlatformArchitectureglibcC StandardStatus
CentOS 6.9x86_642.12C99Verified
CentOS 7x86_642.17C11Verified
Amazon Linux 2x86_642.26C11Verified
Ubuntu 20.04 LTSx86_642.31C11Verified
Debian Bullseyex86_642.31C11Verified
Windowsx64N/AC11Verified
macOSx86_64 / arm64N/AC11Verified

Embedded Systems

This SDK can be integrated into embedded systems with network connectivity.

Cross-Compilation

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 .

Memory Requirements

ComponentApproximate Size
Static library (MinSizeRel)~50 KB
Runtime heap per client~8 KB
TTS response bufferVariable (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.
1

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
2

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
3

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

FunctionDescription
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

FunctionDescription
typecast_text_to_speech(client, request)Convert text to speech audio
typecast_tts_response_free(response)Free TTS response memory

Voice Functions

FunctionDescription
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

FunctionDescription
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

FieldTypeRequiredDescription
textconst char*Text to synthesize (max 2000 chars)
voice_idconst char*Voice ID (format: tc_* or uc_*)
modelTypecastModelTTS 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

FieldTypeDescription
audio_datauint8_t*Generated audio data
audio_sizesize_tSize of audio data in bytes
durationfloatAudio duration in seconds
formatTypecastAudioFormatAudio format (wav or mp3)