Skip to main content

client.tts.createStream(request)

Returns a Readable stream. The first chunk arrives quickly — use this for real-time playback where you want to start playing audio before the full response is ready.
import UpliftAI from '@upliftai/sdk-js';
import { createWriteStream } from 'fs';

const client = new UpliftAI({
  apiKey: 'your-api-key',
});

const { stream, metadata } = await client.tts.createStream({
  text: 'اردو میں ایک لمبا جملہ، جو سٹریمنگ کی جانچ کے لیے ہے',
  voiceId: 'v_meklc281',
  outputFormat: 'MP3_22050_64',
});

console.log(`Request ID: ${metadata.requestId}`);
console.log(`Content-Type: ${metadata.contentType}`);

const fileStream = createWriteStream('output.mp3');
let totalBytes = 0;

for await (const chunk of stream) {
  totalBytes += chunk.length;
  fileStream.write(chunk);
  process.stdout.write(`\rReceived ${totalBytes} bytes`);
}

fileStream.end();
console.log('\nDone!');

Request Parameters

ParameterTypeRequiredDescription
textstringYesText to synthesize
voiceIdstringYesVoice profile ID
outputFormatstringNoAudio format — defaults to WAV_22050_32
phraseReplacementConfigIdstringNoID from phrase replacements

Response

FieldTypeDescription
streamReadableNode.js readable stream of audio chunks
metadata.requestIdstringRequest ID for debugging
metadata.contentTypestringMIME type of the audio
metadata.sampleRatenumberAudio sample rate

When to Use Streaming vs Sync

MethodBest For
tts.create()Batch processing, saving files, when you need the full buffer
tts.createStream()Real-time playback, large texts, when first-byte latency matters