Skip to main content

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

FieldTypeDescription
mediaIdstringUnique ID to retrieve the audio later
tokenstringAuth token for retrieval
temporaryUrlstringPre-signed URL — no auth needed, pass to frontends

Request Parameters

ParameterTypeRequiredDescription
textstringYesText to synthesize
voiceIdstringYesVoice profile ID
outputFormatstringNoAudio format — defaults to WAV_22050_32
phraseReplacementConfigIdstringNoID 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)