Documentation Navigation
Getting Started
API Reference
Resources
Voice API
Text-to-speech, voice cloning, and emotion control. 17 models, 168 voices. From $0.001/clip.
POST /v1/generations/voice
Generate speech from text. Returns synchronously for short text, async for long-form.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model key (e.g. "cosyvoice2", "elevenlabs-v2", "kokoro-v1"). |
prompt | string | Yes | Text to speak. |
voice | string | No | Voice preset name (e.g. "alloy", "nova"). See GET /v1/voices. |
speed | number | No | Speaking speed. 0.5 to 2.0. Default: 1.0. |
ref_audio_url | string (URL) | No | Reference audio URL for voice cloning. |
emotion | string | No | Emotion control: "neutral", "happy", "sad", "excited". Model-dependent. |
confirm | boolean | No | Set to false for cost estimate only. Default: true. |
Response fields
| Field | Type | Description |
|---|---|---|
id | string | Generation ID. |
status | string | "completed" or "failed". |
url | string | CDN URL of the generated audio (MP3). |
cost.micro | integer | Cost in microdollars. |
cost.display | string | Human-readable cost. |
metadata.duration | number | Audio duration in seconds. |
metadata.sample_rate | integer | Audio sample rate in Hz. |
metadata.voice | string | Voice preset used. |
Code examples
curl
curl -X POST https://api.fairstack.ai/v1/generations/voice \
-H "Authorization: Bearer $FAIRSTACK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "cosyvoice2",
"prompt": "Welcome to FairStack. The best AI models, at fair prices.",
"voice": "alloy"
}' Python
from fairstack import FairStack
client = FairStack(api_key="fs_live_YOUR_KEY")
result = client.generate.voice(
model="cosyvoice2",
prompt="Welcome to FairStack. The best AI models, at fair prices.",
voice="alloy"
)
print(result.url) # https://media.fairstack.ai/voice/...
print(result.cost) # $0.001 Node.js
import { FairStack } from "fairstack";
const client = new FairStack({ apiKey: "fs_live_YOUR_KEY" });
const result = await client.generate.voice({
model: "cosyvoice2",
prompt: "Welcome to FairStack. The best AI models, at fair prices.",
voice: "alloy",
});
console.log(result.url); // https://media.fairstack.ai/voice/...
console.log(result.cost); // { micro: 1000, display: "$0.001" } Response
{
"id": "gen_voice_abc",
"status": "completed",
"url": "https://media.fairstack.ai/voice/.../output.mp3",
"model": "cosyvoice2",
"modality": "voice",
"cost": {
"micro": 1000,
"display": "$0.001",
"currency": "USD"
},
"metadata": {
"duration": 3.2,
"sample_rate": 44100,
"voice": "alloy"
}
} Cost estimation
Set confirm: false to get the exact cost without generating audio.
curl -X POST https://api.fairstack.ai/v1/generations/voice \
-H "Authorization: Bearer $FAIRSTACK_API_KEY" \
-d '{ "model": "cosyvoice2", "prompt": "test", "confirm": false }'
# Response: { "estimated_cost": { "micro": 1000, "display": "$0.001" } } Voice cloning
Provide a reference audio URL to clone any voice. Works with models that support cloning (CosyVoice 2, FishSpeech).
{
"model": "cosyvoice2",
"prompt": "Your cloned voice reads this sentence perfectly.",
"ref_audio_url": "https://example.com/my-voice-sample.mp3"
} For best results, use a 10-30 second clear audio sample with minimal background noise. See the Voice Cloning Guide for details.
GET /v1/voices
List available voice presets for a given model.
curl https://api.fairstack.ai/v1/voices \
-H "Authorization: Bearer $FAIRSTACK_API_KEY" Returns an array of voice objects with name, language, gender, and preview_url.
Next steps
- Voice Guide -- 168+ voices, streaming, SSML
- Voice Cloning Guide -- reference audio, best practices
- Voice Models -- browse all 17 voice models