Async Text to Speech - Uplift AI API Docs
client.tts.enqueue(request)
Enqueue a TTS job and retrieve the audio later. Returns a temporaryUrl you can pass directly to a frontend, WhatsApp, or <audio> element — no auth required.
import UpliftAI from '@upliftai/sdk-js';
import { createWriteStream } from 'fs';
const client = new UpliftAI({
apiKey: 'your-api-key',
});
// Enqueue the job
const { mediaId, temporaryUrl } = await client.tts.enqueue({
text: 'یہ ایک async ٹیسٹ ہے۔ آڈیو بعد میں حاصل کی جائے گی۔',
voiceId: 'v_meklc281',
outputFormat: 'MP3_22050_64',
});
console.log(`mediaId: ${mediaId}`);
// Option 1: Use the temporary URL directly (no auth needed)
// Pass this to a frontend or external system (e.g. WhatsApp)
console.log(`temporaryUrl: ${temporaryUrl}`);
// Option 2: Retrieve audio later via SDK
const { stream, metadata } = await client.tts.retrieve(mediaId);
console.log(`Content-Type: ${metadata.contentType}`);
console.log(`Sample Rate: ${metadata.sampleRate}`);
const fileStream = createWriteStream('output.mp3');
let totalBytes = 0;
for await (const chunk of stream) {
totalBytes += chunk.length;
fileStream.write(chunk);
}
fileStream.end();
console.log(`Retrieved ${totalBytes} bytes`);
client.tts.enqueueStream(request)
Same as enqueue() but uses the streaming endpoint for the initial synthesis.
const { mediaId, temporaryUrl } = await client.tts.enqueueStream({
text: 'سٹریمنگ کے ساتھ async',
voiceId: 'v_meklc281',
});
client.tts.retrieve(mediaId)
Fetch the audio for a previously enqueued job.
const { stream, metadata } = await client.tts.retrieve(mediaId);
Enqueue Response
| Field | Type | Description |
|---|---|---|
mediaId |
string |
Unique ID to retrieve the audio later |
token |
string |
Auth token for retrieval |
temporaryUrl |
string |
Pre-signed URL — no auth needed, pass to frontends |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text |
string |
Yes | Text to synthesize |
voiceId |
string |
Yes | Voice profile ID |
outputFormat |
string |
No | Audio format — defaults to WAV_22050_32 |
phraseReplacementConfigId |
string |
No | ID from phrase replacements |
When to Use Async
- Long texts where synthesis takes time
- Background processing pipelines
- When you need a shareable URL (WhatsApp messages, emails, frontend
<audio>tags)