What is LlamaIndex?
LlamaIndex is a Python framework for building context-augmented LLM applications. It provides tools for data ingestion, indexing, and querying, as well as agent capabilities that can use external tools.
With the Typecast tool, your LlamaIndex agents can:
- Generate speech from text with customizable voices
- Control emotions (happy, sad, angry, whisper, and more)
- Discover voices by filtering model, gender, age, or use case
- Create reproducible audio using seed parameters
Prerequisites
Before you start, make sure you have:
| Requirement | Version |
|---|---|
| Python | 3.11+ |
| LlamaIndex Core | 0.13–0.14 |
| Typecast API Key | Get yours here |
Installation
Install the Typecast tool for LlamaIndex:
pip install llama-index-tools-typecast
Quick Start
Here's a minimal example of using Typecast TTS with a LlamaIndex agent:
from llama_index.tools.typecast import TypecastToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
# Initialize the Typecast tool
speech_tool = TypecastToolSpec(api_key="your-typecast-key")
# Create an agent with Typecast capabilities
agent = FunctionAgent(
tools=speech_tool.to_tool_list(),
llm=OpenAI(model="gpt-4o-mini"),
)
# Generate speech through the agent
result = await agent.run(
'Create speech from the text "Hello world!" with a happy emotion '
'and output the file to "speech.wav"'
)
print(result)
Available Tools
The TypecastToolSpec provides three tools for your agents:
Convert text to speech with emotion, pitch, tempo control, and reproducible results.
List all available Typecast voices with optional filtering.
Get details of a specific voice by ID.
Direct Usage (Without Agent)
You can also use the tool directly for more control:
Discover Voices
from llama_index.tools.typecast import TypecastToolSpec
speech_tool = TypecastToolSpec(api_key="your-typecast-key")
# Get all available voices with optional filters
voices = speech_tool.get_voices(
model="ssfm-v30",
gender="female",
age="young_adult",
use_case="Audiobook"
)
print(f"Found {len(voices)} voices")
for voice in voices:
print(f"{voice['voice_name']} ({voice['voice_id']})")
Get Voice Details
# Get specific voice information
voice = speech_tool.get_voice("tc_62a8975e695ad26f7fb514d1")
print(f"Voice: {voice['voice_name']}")
print(f"Gender: {voice.get('gender')}, Age: {voice.get('age')}")
print(f"Use cases: {voice.get('use_cases')}")
# Models include supported emotions
for model in voice["models"]:
print(f"Model {model['version']}: emotions = {model['emotions']}")
Generate Speech
# Text-to-speech with full parameter control
output_path = speech_tool.text_to_speech(
text="Hello world! This is a test.",
voice_id="tc_62a8975e695ad26f7fb514d1",
output_path="speech.wav",
model="ssfm-v30",
language="eng",
emotion_preset="happy",
emotion_intensity=1.5,
volume=100,
audio_pitch=0,
audio_tempo=1.0,
audio_format="wav",
seed=42, # Unsigned seed for reproducible results
)
print(f"Audio saved to: {output_path}")
Features
Multiple Voice Models
Typecast supports multiple AI voice model versions:
| Model | Description |
|---|---|
ssfm-v30 | Latest model with enhanced emotions (recommended) |
ssfm-v21 | Legacy model for backward compatibility |
Emotion Control
Control the emotional expression of generated speech:
| Emotion | ssfm-v30 | ssfm-v21 |
|---|---|---|
normal | ✓ | ✓ |
happy | ✓ | ✓ |
sad | ✓ | ✓ |
angry | ✓ | ✓ |
whisper | ✓ | - |
toneup | ✓ | - |
tonedown | ✓ | - |
Use emotion_intensity (0.0 - 2.0) to adjust expressiveness. Values greater than 1.0 increase intensity.
Multi-Language Support
Typecast supports 27+ languages including:
- English (
eng) - Korean (
kor) - Japanese (
jpn) - Chinese (
zho) - Spanish (
spa) - And many more...
Audio Customization
Fine-tune your audio output:
| Parameter | Range | Description |
|---|---|---|
volume | 0 - 200 | Audio volume as percentage |
audio_pitch | -12 to 12 | Semitone adjustment |
audio_tempo | 0.5 - 2.0 | Playback speed (recommended: 0.85 - 1.15) |
audio_format | wav, mp3 | Output format |
seed | uint32 | Unsigned integer seed for reproducible audio generation (≥ 0) |
Complete Agent Example
Here's a full example with an agent that can discover voices and generate speech:
import os
from llama_index.tools.typecast import TypecastToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
# Set up API keys
os.environ["OPENAI_API_KEY"] = "your-openai-key"
# Initialize Typecast tool
speech_tool = TypecastToolSpec(api_key="your-typecast-key")
# Create agent with Typecast capabilities
agent = FunctionAgent(
tools=speech_tool.to_tool_list(),
llm=OpenAI(model="gpt-4o-mini"),
)
# Let the agent discover voices and generate speech
result = await agent.run(
'Get the list of available voices, select the first female voice, '
'and use it to create speech from the text "Welcome to Typecast!" '
'with a happy emotion, saving to "welcome.wav"'
)
print(result)
Troubleshooting
API key not found error
- Ensure you're passing the correct API key to
TypecastToolSpec - Verify your key at Typecast API Console
- Check for extra spaces in the key
No audio file created
- Check that the output path is writable
- Verify your API key has sufficient credits
- Ensure the voice_id is valid
Import errors
- Make sure you installed
llama-index-tools-typecast - For agent usage, also install
llama-index-llms-openaior your preferred LLM provider - Verify Python version is 3.11 or higher
- Verify
llama-index-coreis version 0.13 or 0.14
Agent not using the tools correctly
- Be specific in your prompts about what you want the agent to do
- Break down complex tasks into simpler steps
- Provide example output paths for audio files