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`);