Python: If you have an older version, upgrade with pip install --upgrade typecast-python
Javascript: If you have an older version, upgrade with npm update @neosapience/typecast-js
C#: Update with dotnet add package typecast-csharp
Java: Update the version in your pom.xml or build.gradle
Kotlin: Update the version in your build.gradle.kts
Rust: Update the version in your Cargo.toml
2
Import and Initialize
from typecast import Typecastfrom typecast.models import TTSRequest, SmartPrompt# Initialize clientclient = Typecast(api_key="YOUR_API_KEY")# Convert text to speechresponse = client.text_to_speech(TTSRequest( text="Everything is going to be okay.", model="ssfm-v30", voice_id="tc_672c5f5ce59fac2a48faeaee", prompt=SmartPrompt( emotion_type="smart", previous_text="I just got the best news!", next_text="I can't wait to celebrate!" )))# Save audio filewith open('typecast.wav', 'wb') as f: f.write(response.audio_data)
You can set up your API key in two ways:
Configure it directly in your application code
Set it as a shell environment variable
# Set for current sessionexport TYPECAST_API_KEY='YOUR_API_KEY'
import requestsimport osapi_key = os.environ.get("TYPECAST_API_KEY", "YOUR_API_KEY")url = "https://api.typecast.ai/v1/text-to-speech"headers = {"X-API-KEY": api_key, "Content-Type": "application/json"}payload = { "text": "Everything is going to be okay.", "model": "ssfm-v30", "voice_id": "tc_672c5f5ce59fac2a48faeaee", "prompt": { "emotion_type": "smart", "previous_text": "I just got the best news!", "next_text": "I can't wait to celebrate!" }}response = requests.post(url, headers=headers, json=payload)if response.status_code == 200: with open('typecast.wav', 'wb') as f: f.write(response.content) print("Audio file saved as typecast.wav")else: print(f"Error: {response.status_code} - {response.text}")
To use Typecast effectively, you need access to voice IDs. The /v2/voices endpoint provides a complete list of available voices with their unique identifiers, names, supported models, and emotions.You can filter voices by model, gender, age, and use cases using optional query parameters.
You can explore our complete voice catalog in more detail on the Voices page, where you’ll find additional information about each voice’s characteristics, sample audio clips, and recommended use cases.
SDK
Direct API
from typecast import Typecastfrom typecast.models import VoicesV2Filter, TTSModel# Initialize clientclient = Typecast(api_key="YOUR_API_KEY")# Get all voices (optionally filter by model, gender, age, use_cases)voices = client.voices_v2(VoicesV2Filter(model=TTSModel.SSFM_V30))print(f"Found {len(voices)} voices:")for voice in voices: for model in voice.models: print(f"ID: {voice.voice_id}, Name: {voice.voice_name}, Model: {model.version.value}, Emotions: {', '.join(model.emotions)}")
For low-latency applications, use the streaming endpoint to play audio as chunks arrive — no need to wait for full synthesis.WAV streaming format: 32000 Hz, 16-bit, mono PCM. The first chunk includes a 44-byte WAV header; subsequent chunks are raw PCM only.
SDK
Direct API
# pip install typecast-python sounddeviceimport sounddevice as sdfrom typecast import Typecastfrom typecast.models import TTSRequestStream, OutputStreamclient = Typecast(api_key="YOUR_API_KEY")request = TTSRequestStream( text="Stream this text as audio in real time.", model="ssfm-v30", voice_id="tc_672c5f5ce59fac2a48faeaee", output=OutputStream(audio_format="wav"))with sd.RawOutputStream(samplerate=32000, channels=1, dtype="int16") as player: buf, first = bytearray(), True for chunk in client.text_to_speech_stream(request): if first: chunk = chunk[44:] # Skip 44-byte WAV header first = False buf.extend(chunk) n = len(buf) - (len(buf) % 2) # int16 alignment if n: player.write(bytes(buf[:n])) del buf[:n]
See each SDK documentation for more languages (Go, Rust, Swift, C#, Kotlin, C) with real-time playback examples.
# pip install requests sounddeviceimport requestsimport sounddevice as sdimport osapi_key = os.environ.get("TYPECAST_API_KEY", "YOUR_API_KEY")response = requests.post( "https://api.typecast.ai/v1/text-to-speech/stream", headers={"X-API-KEY": api_key, "Content-Type": "application/json"}, json={ "text": "Stream this text as audio in real time.", "model": "ssfm-v30", "voice_id": "tc_672c5f5ce59fac2a48faeaee", }, stream=True)response.raise_for_status()with sd.RawOutputStream(samplerate=32000, channels=1, dtype="int16") as player: buf, first = bytearray(), True for chunk in response.iter_content(chunk_size=4096): if not chunk: continue if first: chunk = chunk[44:] # Skip WAV header first = False buf.extend(chunk) n = len(buf) - (len(buf) % 2) if n: player.write(bytes(buf[:n])) del buf[:n]
Parameter
Type
Range
Default
Description
audio_pitch
integer
-12–12
0
Pitch adjustment in semitones.
audio_tempo
number
0.5–2.0
1.0
Speed multiplier.
audio_format
string
wav, mp3
wav
Output audio format.
volume and target_lufs are not supported in streaming mode.