Audio API
The Audio API provides powerful Text-to-Speech (TTS) capabilities, supporting multi-language, high-quality natural voice synthesis.
Endpoint
Text-to-Speech (TTS)
POST https://aiapi.services/v1/audio/speechAuthentication
All requests must include your API key in the HTTP header:
Authorization: Bearer YOUR_API_KEYSupported Models
Text-to-Speech (TTS)
text-to-speech-multilingual- Multilingual TTS supporting natural voice synthesis in multiple languagestext-to-speech-neural- Neural network TTS with high-quality natural voice synthesistext-to-speech-001- Standard TTS model for basic text-to-speech functionalitytext-to-speech-standard- Standard TTS version with stable voice synthesis service
See Available Models for the complete model list.
Text-to-Speech
Request Parameters
Required Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Model ID, e.g., text-to-speech-001 |
input | string | Text content to convert to speech |
voice | string | Voice type: alloy, echo, fable, onyx, nova, shimmer |
Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
response_format | string | mp3 | Output format: mp3, opus, aac, flac, wav, pcm |
speed | number | 1.0 | Speech speed (0.25 - 4.0) |
Code Examples
cURL
curl https://aiapi.services/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-to-speech-001",
"input": "The weather is nice today, perfect for a walk.",
"voice": "alloy",
"speed": 1.0
}' \
--output speech.mp3Response Format
Success Response
The response is binary audio data (not JSON format). HTTP response headers include:
Content-Type: audio/mpeg # MP3 format
Content-Type: audio/opus # Opus format
Content-Type: audio/aac # AAC format
Content-Type: audio/flac # FLAC format
Content-Type: audio/wav # WAV format
Content-Type: audio/pcm # PCM format
Content-Length: 45678 # File size (bytes)Usage:
Save to File
# Save as file
with open('output.mp3', 'wb') as f:
f.write(response.content)Audio Format Comparison
| Format | File Size | Quality | Compatibility | Recommended Use |
|---|---|---|---|---|
| mp3 | Medium | Good | Excellent | General purpose, default |
| opus | Smallest | Excellent | Good | Bandwidth-limited, real-time |
| aac | Medium | Excellent | Good | iOS/Mac applications |
| flac | Large | Lossless | Fair | High-quality audio needs |
| wav | Largest | Lossless | Excellent | Professional audio |
| pcm | Largest | Lossless | Poor | Low-level audio development |
File Size Estimation
Approximate relationship between text length and audio file size (MP3 format):
| Text Length | Audio Duration | MP3 File Size |
|---|---|---|
| 100 chars | ~10 seconds | ~20KB |
| 500 chars | ~50 seconds | ~100KB |
| 1000 chars | ~100 seconds | ~200KB |
| 4096 chars (max) | ~400 seconds | ~800KB |
Error Response
When requests fail, JSON-formatted error is returned. See Error Handling documentation for details.
{
"code": "invalid_request_error",
"message": "Invalid parameter: input text too long",
"data": null
}Common Errors:
input_too_long- Text exceeds maximum length (4096 characters)invalid_voice- Unsupported voice typequota_not_enough- Insufficient quota
Voice Types
| Voice Type | Characteristics | Use Cases |
|---|---|---|
| alloy | Neutral, clear | General purpose |
| echo | Male, steady | Business, news |
| fable | Warm, friendly | Storytelling |
| onyx | Deep, authoritative | Formal occasions |
| nova | Female, energetic | Advertising, marketing |
| shimmer | Soft, elegant | Assistant, customer service |
Best Practices
Performance Optimization:
- Recommended maximum text length per request: 4096 characters
- For longer texts, process in segments
- Use appropriate speech speed; default 1.0 is most natural
Important Notes:
- Generated audio file size is proportional to text length
- Generation time may vary slightly between voice types
- Use HTTPS to ensure secure audio data transmission
Related Resources
- Authentication - Learn how to get and use API keys
- Available Models - View complete model list and pricing
- Music API - AI music generation features
Last updated on