Code Examples
Ready-to-use examples in multiple languages
Python
Basic Generation (Premium)
import requests
import time
API_KEY = "tts_YOUR_KEY"
BASE_URL = "https://aitts.theproductivepixel.com/api/v1"
def generate_speech(text: str, voice: str = "google:en-US-Chirp3-HD-Charon") -> str:
"""Generate speech using premium Chirp3-HD voice."""
response = requests.post(
f"{BASE_URL}/tts",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"text": text, "voice": voice, "model_type": "premium"}
)
response.raise_for_status()
job_id = response.json()["data"]["job_id"]
# Poll for completion
while True:
status = requests.get(
f"{BASE_URL}/tts/{job_id}",
headers={"Authorization": f"Bearer {API_KEY}"}
).json()["data"]
if status["status"] == "completed":
return status["audio_url"]
if status["status"] == "failed":
raise Exception(status.get("error", {}).get("message"))
time.sleep(1)
audio_url = generate_speech("Hello from the Charon voice!")
print(f"Audio: {audio_url}")With Idempotency Key
import uuid
def generate_safe(text: str, idempotency_key: str = None):
"""Safe retries with idempotency key."""
response = requests.post(
f"{BASE_URL}/tts",
headers={
"Authorization": f"Bearer {API_KEY}",
"Idempotency-Key": idempotency_key or str(uuid.uuid4())
},
json={"text": text, "voice": "google:en-US-Chirp3-HD-Charon", "model_type": "premium"}
)
return response.json()["data"]Node.js / TypeScript
Basic Generation (Premium)
const API_KEY = "tts_YOUR_KEY";
const BASE_URL = "https://aitts.theproductivepixel.com/api/v1";
async function generateSpeech(
text: string,
voice = "google:en-US-Chirp3-HD-Charon"
): Promise<string> {
const res = await fetch(`${BASE_URL}/tts`, {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ text, voice, model_type: "premium" })
});
const { data: job } = await res.json();
// Poll for completion
while (true) {
const statusRes = await fetch(`${BASE_URL}/tts/${job.job_id}`, {
headers: { "Authorization": `Bearer ${API_KEY}` }
});
const { data: status } = await statusRes.json();
if (status.status === "completed") return status.audio_url;
if (status.status === "failed") throw new Error(status.error?.message);
await new Promise(r => setTimeout(r, 1000));
}
}
const url = await generateSpeech("Hello from TypeScript!");cURL
Submit Job (Premium)
curl -X POST https://aitts.theproductivepixel.com/api/v1/tts \
-H "Authorization: Bearer tts_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Hello world!", "voice": "google:en-US-Chirp3-HD-Charon", "model_type": "premium"}'Check Status
curl https://aitts.theproductivepixel.com/api/v1/tts/JOB_ID \
-H "Authorization: Bearer tts_YOUR_KEY"List Voices
curl "https://aitts.theproductivepixel.com/api/v1/voices?model_type=premium" \
-H "Authorization: Bearer tts_YOUR_KEY"Multi-Speaker Dialogue (Ultra)
Ultra voices support multi-speaker conversations. Use the Speaker 1/Speaker 2 format with an optional instruction line.
Two Speakers
response = requests.post(
f"{BASE_URL}/tts",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"text": "Instruction: Be cheerful and friendly.\nSpeaker 1: How are you today?\nSpeaker 2: I'm doing great, thanks for asking!",
"model_type": "ultra",
"speaker_type": "multi",
"voice_speaker_1": "google:en-US-kore",
"voice_speaker_2": "google:en-US-puck"
}
)Example Chirp3-HD Voices
Format: {locale}-Chirp3-HD-{voice}
AlgiebaAoedeCharonFenrirKorePuckLedaOrusZephyr
Example: en-US-Chirp3-HD-Charon
Browse the full voice library for all available options.
Rate Limits
| Free | 10 requests / 15 min |
| Premium | 100 requests / 15 min |
| Enterprise | 1,000 requests / 15 min |
Back to Documentation
© 2026 AI TTS Microservice. All rights reserved.