Text to Speech API Integration: Developer's Complete Guide
Looking to add text-to-speech capabilities to your application? This developer guide covers everything you need to integrate the DubVoice.ai TTS API — from authentication to production best practices.
Why Use a TTS API?
Building text-to-speech from scratch requires massive datasets, expensive GPU infrastructure, and deep ML expertise. A TTS API gives you:
- Production-ready voices — 50+ natural voices out of the box
- Multi-language support — 30+ languages with one API
- Scalability — Handle thousands of requests without infrastructure concerns
- Continuous improvement — Voice quality improves without any work on your end
Quick Start
Authentication
All API requests require an API key. Get yours from the DubVoice.ai dashboard under Settings > API Keys.
Basic Request
curl -X POST https://dubvoice.ai/api/v1/tts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, welcome to our application!",
"voice_id": "voice_rachel",
"language": "en"
}'Response
The API returns an audio file (MP3 by default) along with metadata including character count and processing time.
Integration Patterns
Pattern 1: On-Demand Generation
Generate audio when the user requests it. Best for interactive applications, chatbots, and accessibility features.
Pattern 2: Pre-Generation
Generate and cache audio for known content. Best for e-learning platforms, IVR systems, and static content.
Pattern 3: Streaming
For real-time applications where low latency matters. Generate and stream audio chunks as they're produced.
Best Practices
- Cache aggressively — If the same text is requested multiple times, serve from cache
- Handle rate limits — Implement exponential backoff for 429 responses
- Validate input — Check text length and content before sending to the API
- Monitor usage — Track character consumption to avoid unexpected costs
- Use webhooks — For long-form content, use async generation with callbacks
Error Handling
Always implement proper error handling:
- 400 — Invalid request (check text length, voice ID, language)
- 401 — Invalid or expired API key
- 429 — Rate limit exceeded (implement backoff)
- 500 — Server error (retry with exponential backoff)
Pricing for API Usage
API usage consumes credits from your DubVoice.ai balance at the same rate as the web interface. One credit equals one character. Plans range from 250K credits ($4.99) to 10M credits ($31.99).
Common Use Cases
- Mobile apps — Add voice narration to reading apps, news apps, or navigation
- Web applications — Accessibility features, audio content, user notifications
- IoT devices — Smart home announcements, embedded voice responses
- Games — NPC dialogue, narrator voice, dynamic story content
- SaaS platforms — Audio versions of reports, dashboards, and alerts
Getting Started
- Sign up at dubvoice.ai and get your API key
- Test with a simple cURL request
- Integrate into your application using your preferred language
- Test across different voices and languages
- Deploy and monitor usage
Check our full API documentation at dubvoice.ai/api-docs for complete endpoint reference, voice catalog, and language codes.
Try DubVoice.ai Today
AI text-to-speech, Veo 3 video, images, translation & content writing — all in one platform. No subscription required.