{% extends "base.html" %} {% block title %}TTSFM API Documentation{% endblock %} {% block extra_css %} {% endblock %} {% block content %}
Complete reference for the TTSFM Text-to-Speech API. Free, simple, and powerful.
The TTSFM API provides a modern, OpenAI-compatible interface for text-to-speech generation. It supports multiple voices, audio formats, and includes advanced features like text length validation and intelligent auto-combine functionality.
{{ request.url_root }}api/
Currently, the API supports optional API key authentication. If configured, include your API key in the request headers.
Authorization: Bearer YOUR_API_KEY
TTSFM includes built-in text length validation to ensure compatibility with TTS models. The default maximum length is 4096 characters, but this can be customized.
max_length: Maximum allowed characters (default: 4096)validate_length: Enable/disable validation (default: true)preserve_words: Avoid splitting words when chunking (default: true)Get list of available voices.
{
"voices": [
{
"id": "alloy",
"name": "Alloy",
"description": "Alloy voice"
},
{
"id": "echo",
"name": "Echo",
"description": "Echo voice"
}
],
"count": 6
}
Get list of supported audio formats.
{
"formats": [
{
"id": "mp3",
"name": "MP3",
"mime_type": "audio/mp3",
"description": "MP3 audio format"
}
],
"count": 6
}
Validate text length and get splitting suggestions.
{
"text": "Your text to validate",
"max_length": 4096
}
{
"text_length": 5000,
"max_length": 4096,
"is_valid": false,
"needs_splitting": true,
"suggested_chunks": 2,
"chunk_preview": [
"First chunk preview...",
"Second chunk preview..."
]
}
Generate speech from text.
{
"text": "Hello, world!",
"voice": "alloy",
"format": "mp3",
"instructions": "Speak cheerfully",
"max_length": 4096,
"validate_length": true
}
text (required): Text to convert to speechvoice (optional): Voice ID (default: "alloy")format (optional): Audio format (default: "mp3")instructions (optional): Voice modulation instructionsmax_length (optional): Maximum text length (default: 4096)validate_length (optional): Enable validation (default: true)Returns audio file with appropriate Content-Type header.
The TTSFM Python package includes built-in long text splitting functionality for developers who need fine-grained control:
from ttsfm import TTSClient, Voice, AudioFormat
# Create client
client = TTSClient()
# Generate speech from long text (automatically splits into separate files)
responses = client.generate_speech_long_text(
text="Very long text that exceeds 4096 characters...",
voice=Voice.ALLOY,
response_format=AudioFormat.MP3,
max_length=2000,
preserve_words=True
)
# Save each chunk as separate files
for i, response in enumerate(responses, 1):
response.save_to_file(f"part_{i:03d}.mp3")
--split-long-text flag for command-line usage/v1/audio/speech is recommended
as it automatically handles long text and returns a single seamless audio file.
Generate a single combined audio file from long text. Automatically splits text into chunks, generates speech for each chunk, and combines them into one seamless audio file.
{
"text": "Very long text that exceeds the limit...",
"voice": "alloy",
"format": "mp3",
"instructions": "Optional voice instructions",
"max_length": 4096,
"preserve_words": true
}
Returns a single audio file containing all chunks combined seamlessly.
X-Chunks-Combined: Number of chunks that were combinedX-Original-Text-Length: Original text length in charactersX-Audio-Size: Final audio file size in bytesEnhanced OpenAI-compatible endpoint with auto-combine feature. Automatically handles long text by splitting and combining audio chunks when needed.
{
"model": "gpt-4o-mini-tts",
"input": "Text of any length...",
"voice": "alloy",
"response_format": "mp3",
"instructions": "Optional voice instructions",
"speed": 1.0,
"auto_combine": true,
"max_length": 4096
}
true: Automatically split long text and combine audio chunks into a single filefalse: Return error if text exceeds max_length (standard OpenAI behavior)X-Auto-Combine: Whether auto-combine was enabled (true/false)X-Chunks-Combined: Number of audio chunks combined (1 for short text)X-Original-Text-Length: Original text length (for long text processing)X-Audio-Format: Audio format of the responseX-Audio-Size: Audio file size in bytes# Short text (works normally)
curl -X POST {{ request.url_root }}v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Hello world!",
"voice": "alloy"
}'
# Long text with auto-combine (default)
curl -X POST {{ request.url_root }}v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Very long text...",
"voice": "alloy",
"auto_combine": true
}'
# Long text without auto-combine (will error)
curl -X POST {{ request.url_root }}v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Very long text...",
"voice": "alloy",
"auto_combine": false
}'
# Python example
import requests
response = requests.post(
"{{ request.url_root }}api/generate-combined",
json={
"text": "Your very long text content here...",
"voice": "nova",
"format": "mp3",
"max_length": 2000
}
)
if response.status_code == 200:
with open("combined_audio.mp3", "wb") as f:
f.write(response.content)
chunks = response.headers.get('X-Chunks-Combined')
print(f"Combined {chunks} chunks into single file")