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
2
Import and Initialize
Copy
Ask AI
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
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": "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 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 /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
Copy
Ask AI
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)}")