Skip to main content

Official Typecast Python SDK - Convert text to lifelike speech using AI-powered voices

Project description

Typecast SDK for Python

The official Python SDK for the Typecast Text-to-Speech API

Convert text to lifelike speech using AI-powered voices

PyPI version License Python

Documentation | API Reference | Get API Key


Table of Contents


Installation

pip install typecast-python

Quick Start

from typecast import Typecast
from typecast.models import TTSRequest

client = Typecast(api_key="YOUR_API_KEY")

response = client.text_to_speech(TTSRequest(
    text="Hello! I'm your friendly text-to-speech assistant.",
    model="ssfm-v30",
    voice_id="tc_672c5f5ce59fac2a48faeaee"
))

with open("output.wav", "wb") as f:
    f.write(response.audio_data)

print(f"Saved: output.wav ({response.duration}s)")

Features

Feature Description
Multiple Models Support for ssfm-v21 and ssfm-v30 AI voice models
37 Languages English, Korean, Japanese, Chinese, Spanish, and 32 more
Emotion Control Preset emotions or smart context-aware inference
Audio Customization Volume, pitch, tempo, and format (WAV/MP3)
Voice Discovery Filter voices by model, gender, age, and use cases
Async Support Built-in async client for high-performance applications
Type Hints Full type annotations with Pydantic models

Usage

Configuration

from typecast import Typecast

# Using environment variable (recommended)
# export TYPECAST_API_KEY="your-api-key"
client = Typecast()

# Or pass directly
client = Typecast(
    api_key="your-api-key",
    host="https://api.typecast.ai"  # optional
)

Text to Speech

Basic Usage

from typecast.models import TTSRequest

response = client.text_to_speech(TTSRequest(
    text="Hello, world!",
    voice_id="tc_672c5f5ce59fac2a48faeaee",
    model="ssfm-v30"
))

With Audio Options

from typecast.models import TTSRequest, Output

response = client.text_to_speech(TTSRequest(
    text="Hello, world!",
    voice_id="tc_672c5f5ce59fac2a48faeaee",
    model="ssfm-v30",
    language="eng",
    output=Output(
        volume=120,        # 0-200 (default: 100)
        audio_pitch=2,     # -12 to +12 semitones
        audio_tempo=1.2,   # 0.5x to 2.0x
        audio_format="mp3" # "wav" or "mp3"
    ),
    seed=42  # for reproducible results
))

Voice Discovery

from typecast.models import VoicesV2Filter, TTSModel, GenderEnum, AgeEnum

# Get all voices (V2 API - recommended)
voices = client.voices_v2()

# Filter by criteria
filtered = client.voices_v2(VoicesV2Filter(
    model=TTSModel.SSFM_V30,
    gender=GenderEnum.FEMALE,
    age=AgeEnum.YOUNG_ADULT
))

# Display voice info
print(f"Name: {voices[0].voice_name}")
print(f"Gender: {voices[0].gender}, Age: {voices[0].age}")
print(f"Models: {', '.join(m.version.value for m in voices[0].models)}")

Emotion Control

ssfm-v21: Basic Emotion

from typecast.models import TTSRequest, Prompt

response = client.text_to_speech(TTSRequest(
    text="I'm so excited!",
    voice_id="tc_62a8975e695ad26f7fb514d1",
    model="ssfm-v21",
    prompt=Prompt(
        emotion_preset="happy",  # normal, happy, sad, angry
        emotion_intensity=1.5    # 0.0 to 2.0
    )
))

ssfm-v30: Preset Mode

from typecast.models import TTSRequest, PresetPrompt, TTSModel

response = client.text_to_speech(TTSRequest(
    text="I'm so excited!",
    voice_id="tc_672c5f5ce59fac2a48faeaee",
    model=TTSModel.SSFM_V30,
    prompt=PresetPrompt(
        emotion_type="preset",
        emotion_preset="happy",  # normal, happy, sad, angry, whisper, toneup, tonedown
        emotion_intensity=1.5
    )
))

ssfm-v30: Smart Mode (Context-Aware)

from typecast.models import TTSRequest, SmartPrompt, TTSModel

response = client.text_to_speech(TTSRequest(
    text="Everything is perfect.",
    voice_id="tc_672c5f5ce59fac2a48faeaee",
    model=TTSModel.SSFM_V30,
    prompt=SmartPrompt(
        emotion_type="smart",
        previous_text="I just got the best news!",
        next_text="I can't wait to celebrate!"
    )
))

Async Client

import asyncio
from typecast import AsyncTypecast
from typecast.models import TTSRequest

async def main():
    async with AsyncTypecast(api_key="YOUR_API_KEY") as client:
        response = await client.text_to_speech(TTSRequest(
            text="Hello from async!",
            model="ssfm-v30",
            voice_id="tc_672c5f5ce59fac2a48faeaee"
        ))

        with open("output.wav", "wb") as f:
            f.write(response.audio_data)

asyncio.run(main())

Supported Languages

View all 37 supported languages
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
from typecast.models import LanguageCode

# Auto-detect (recommended)
response = client.text_to_speech(TTSRequest(
    text="こんにちは",
    voice_id="...",
    model="ssfm-v30"
))

# Explicit language
response = client.text_to_speech(TTSRequest(
    text="안녕하세요",
    voice_id="...",
    model="ssfm-v30",
    language=LanguageCode.KOR
))

Error Handling

from typecast import (
    Typecast,
    TypecastError,
    BadRequestError,
    UnauthorizedError,
    PaymentRequiredError,
    NotFoundError,
    UnprocessableEntityError,
    RateLimitError,
    InternalServerError,
)

try:
    response = client.text_to_speech(request)
except UnauthorizedError:
    print("Invalid API key")
except PaymentRequiredError:
    print("Insufficient credits")
except RateLimitError:
    print("Rate limit exceeded - please retry later")
except TypecastError as e:
    print(f"Error {e.status_code}: {e.message}")
Exception Status Code Description
BadRequestError 400 Invalid request parameters
UnauthorizedError 401 Invalid or missing API key
PaymentRequiredError 402 Insufficient credits
NotFoundError 404 Resource not found
UnprocessableEntityError 422 Validation error
RateLimitError 429 Rate limit exceeded
InternalServerError 500 Server error

License

Apache-2.0 © Neosapience

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typecast_python-0.1.7.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typecast_python-0.1.7-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file typecast_python-0.1.7.tar.gz.

File metadata

  • Download URL: typecast_python-0.1.7.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for typecast_python-0.1.7.tar.gz
Algorithm Hash digest
SHA256 6b53f69b9b8a7c6cbe53d6cac1bdb0b8bd7813eb3227bc79523ddf39dbb00cd8
MD5 93eb3387420fb32594bca81b56ea30c6
BLAKE2b-256 6c1b27e459c2120dab76dcea60636d2c2a2b45986da3d6f00af8d6ba77cb6da2

See more details on using hashes here.

File details

Details for the file typecast_python-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: typecast_python-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for typecast_python-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a87d4565b8fd912ac06ceef1e97db765957dab03ddbd7e7d67bb06a71289e115
MD5 6d3d102ee37c67fbe74c9a360bcd77b0
BLAKE2b-256 bc6cf2512a9f63912a07f5dfd2d624c0461850f60e9f63ff8c009446f949e2e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page