Voice API
Text-to-speech synthesis, speech-to-text transcription, and voice model management.
Overview
The Voice API provides text-to-speech (TTS) and speech-to-text (STT) capabilities with multiple backend providers. You can synthesize speech from text, transcribe audio files, manage voice models, and integrate voice directly into agent conversations.
Supported Backends
| Backend | Type | Cost | Notes |
|---|---|---|---|
edge-tts | TTS | Free | Microsoft Edge voices, 400+ voices, many languages |
elevenlabs | TTS | Paid | Premium quality, voice cloning, low latency |
openai-tts | TTS | Paid | OpenAI TTS-1 and TTS-1-HD models |
whisper | STT | Free/Paid | OpenAI Whisper for transcription |
Text-to-Speech (TTS)
Synthesize Speech (JSON)
Returns synthesized audio as a base64-encoded string in a JSON response.
POST /api/v1/voice/synthesize
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to synthesize |
voice | string | No | Voice ID (default: backend-specific) |
backend | string | No | Backend provider (edge-tts, elevenlabs, openai-tts) |
language | string | No | Language code (e.g., en-US, es-MX) |
speed | number | No | Playback speed multiplier (0.5 - 2.0) |
format | string | No | Audio format: mp3, wav, ogg (default: mp3) |
bashcurl -X POST /api/v1/voice/synthesize \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{ "text": "Hello, welcome to Arcanflows.", "voice": "en-US-AriaNeural", "backend": "edge-tts", "format": "mp3" }'
Response:
json{ "audio": "base64_encoded_audio_data...", "format": "mp3", "duration_ms": 2340, "backend": "edge-tts", "voice": "en-US-AriaNeural", "cached": false }
Synthesize Speech (Audio File)
Returns the audio file directly as a binary response.
POST /api/v1/voice/synthesize/audio
Same request body as /synthesize. Response is the raw audio file with appropriate Content-Type header (e.g., audio/mpeg).
Routed Synthesis
Auto-selects the best available backend based on voice, cost, and quality settings.
POST /api/v1/voice/synthesize/routed
POST /api/v1/voice/synthesize/audio/routed
Same request body but omit the backend field. The router selects the optimal backend automatically.
Speech-to-Text (STT)
Transcribe Audio
POST /api/v1/voice/transcribe
Request: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
audio | file | Yes | Audio file (mp3, wav, ogg, webm, m4a) |
language | string | No | Language hint (e.g., en, es) |
backend | string | No | STT backend (default: whisper) |
bashcurl -X POST /api/v1/voice/transcribe \ -H "Authorization: Bearer <your_login_jwt>" \ -F "[email protected]" \ -F "language=en"
Response:
json{ "text": "Hello, I need help with my account.", "language": "en", "duration_ms": 4200, "backend": "whisper", "confidence": 0.95 }
Routed Transcription
POST /api/v1/voice/transcribe/routed
Auto-selects the best STT backend.
Agent Voice Integration
Send Audio to Agent
Send an audio message to an agent conversation. The audio is transcribed and the agent responds as text.
POST /api/v1/agents/:id/chat/audio
Request: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
audio | file | Yes | Audio file to send |
conversation_id | string | No | Existing conversation ID |
bashcurl -X POST /api/v1/agents/agent_abc123/chat/audio \ -H "Authorization: Bearer <your_login_jwt>" \ -F "[email protected]" \ -F "conversation_id=conv_xyz789"
Response:
json{ "conversation_id": "conv_xyz789", "transcription": "What is my account balance?", "response": "Your current account balance is $1,234.56.", "message_id": "msg_abc123" }
Get TTS for Agent Response
Convert an agent's text response to speech.
POST /api/v1/agents/:id/chat/tts
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
message_id | string | Yes | Message ID to convert |
voice | string | No | Voice ID override |
Response: Audio file binary with Content-Type: audio/mpeg.
Voices and Backends
List Available Voices
GET /api/v1/voice/voices
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
backend | string | Filter by backend |
language | string | Filter by language code |
gender | string | Filter by gender (male, female) |
bashcurl /api/v1/voice/voices?backend=edge-tts&language=en \ -H "Authorization: Bearer <your_login_jwt>"
Response:
json{ "voices": [ { "id": "en-US-AriaNeural", "name": "Aria", "language": "en-US", "gender": "female", "backend": "edge-tts", "preview_url": "/api/v1/voice/voices/en-US-AriaNeural/preview" }, { "id": "en-US-GuyNeural", "name": "Guy", "language": "en-US", "gender": "male", "backend": "edge-tts", "preview_url": "/api/v1/voice/voices/en-US-GuyNeural/preview" } ], "total": 2 }
List Voice Backends
GET /api/v1/voice/backends
Returns all configured voice backends and their status.
Voice Service Health
GET /api/v1/voice/health
Returns the health and availability of each voice backend.
TTS Model Management
For self-hosted TTS backends, you can manage installed models.
List All TTS Models
GET /api/v1/voice/tts/models
Returns all available TTS models (installed and remote).
List Installed Models
GET /api/v1/voice/tts/models/installed
Returns only locally installed TTS models.
List Recommended Models
GET /api/v1/voice/tts/models/recommended
Returns a curated list of recommended models by quality and language.
Download Model
POST /api/v1/voice/tts/models/download
Request Body:
json{ "model_name": "tts-piper-en-us-amy-medium" }
Load Model
POST /api/v1/voice/tts/models/load
Request Body:
json{ "model_name": "tts-piper-en-us-amy-medium" }
Delete Model
DELETE /api/v1/voice/tts/models/:model_name
Removes an installed model from disk.
Cache Management
Invalidate Cache
Clear cached TTS audio files.
POST /api/v1/voice/cache/invalidate
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
backend | string | No | Clear cache for specific backend only |
voice | string | No | Clear cache for specific voice only |
all | boolean | No | Clear entire cache |
bashcurl -X POST /api/v1/voice/cache/invalidate \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{"backend": "edge-tts", "all": false}'
Error Codes
| Code | Description |
|---|---|
voice_backend_unavailable | The requested backend is not configured or offline |
voice_not_found | The specified voice ID does not exist |
audio_format_unsupported | The uploaded audio format is not supported |
transcription_failed | STT processing failed |
model_not_installed | The requested TTS model is not installed |
text_too_long | Input text exceeds the maximum length (10,000 characters) |