from typecast.client import Typecastfrom typecast.models import TTSRequest, Prompt# Initialize clientcli = Typecast(api_key="YOUR_API_KEY")# Convert text to speechresponse = cli.text_to_speech(TTSRequest( text="Hello there! I am your friendly text-to-speech agent.", model="ssfm-v21", voice_id="tc_62a8975e695ad26f7fb514d1", prompt=Prompt( emotion_preset="happy", emotion_intensity=2.0 )))# 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
Copy
Ask AI
# Set for current sessionexport TYPECAST_API_KEY='YOUR_API_KEY'
Copy
Ask AI
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": "Hello there! I am your friendly text-to-speech agent.", "model": "ssfm-v21", "voice_id": "tc_62a8975e695ad26f7fb514d1", "prompt": { "preset": "happy", "preset_intensity": 2.0 }}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 browse and select available voice IDs for your requests, please refer to Listing all voices in our API Reference.
To use Typecast effectively, you need access to voice IDs. The /v1/voices endpoint provides a complete list of available voices with their unique identifiers, names, models, and supported emotions.You can also filter voices by model type using the optional model query parameter.
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
Copy
Ask AI
from typecast.client import Typecast# Initialize clientcli = Typecast(api_key="YOUR_API_KEY")# Get all voices (optionally filter by model)voices = cli.get_voices(model="ssfm-v21") # Optional parameterprint(f"Found {len(voices)} voices:")for voice in voices: print(f"ID: {voice.voice_id}, Name: {voice.voice_name}, Emotions: {', '.join(voice.emotions)}")