import requests
import json
# Step 1: Initiate streaming async TTS
url = "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async"
payload = json.dumps({
"voiceId": "v_meklc281",
"text": "سلام، یہ پاکستان کی تاریخ کے بارے میں ہے۔",
"outputFormat": "MP3_22050_128"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
}
response = requests.post(url, headers=headers, data=payload)
result = response.json()
# Step 2: Stream audio with ~300ms first chunk
media_id = result['mediaId']
token = result['token']
audio_url = f"https://api.upliftai.org/v1/synthesis/stream-audio/{media_id}?token={token}"
# This URL supports chunked streaming
# First chunk arrives in ~300ms
// Initiate streaming TTS
async function streamAudio(text) {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_meklc281",
text: text,
outputFormat: "MP3_22050_128"
})
});
const { mediaId, token } = await response.json();
const streamUrl = `https://api.upliftai.org/v1/synthesis/stream-audio/${mediaId}?token=${token}`;
// Create audio element that starts streaming
const audio = new Audio(streamUrl);
audio.play(); // Starts playing as chunks arrive
return audio;
}
curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔",
"voiceId": "v_meklc281",
"phraseReplacementConfigId": "<string>"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'text' => 'سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔',
'voiceId' => 'v_meklc281',
'phraseReplacementConfigId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async"
payload := strings.NewReader("{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"mediaId": "media_abc123xyz",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}{
"message": "Invalid request parameters"
}{
"message": "Rate limit exceeded, please try again later"
}Async Streaming Text to Speech
This endpoint initiates streaming text-to-speech synthesis and immediately returns a mediaId and token. Unlike regular async TTS, this enables chunked streaming with ~300ms first chunk latency when retrieved.
When to use this endpoint:
- Frontend streaming - Stream audio directly to browsers without proxy
- Low-latency playback - Start playing audio before full generation completes
- CDN streaming - Progressive download through content delivery networks
- Mobile apps - Reduce initial buffering time
For best results with Urdu, use Urdu script. For English words within Urdu text, use ASCII characters. Example: “یہ ایک exerted force ہے”
The audio streams progressively when retrieved via the /stream-audio endpoint.
import requests
import json
# Step 1: Initiate streaming async TTS
url = "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async"
payload = json.dumps({
"voiceId": "v_meklc281",
"text": "سلام، یہ پاکستان کی تاریخ کے بارے میں ہے۔",
"outputFormat": "MP3_22050_128"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
}
response = requests.post(url, headers=headers, data=payload)
result = response.json()
# Step 2: Stream audio with ~300ms first chunk
media_id = result['mediaId']
token = result['token']
audio_url = f"https://api.upliftai.org/v1/synthesis/stream-audio/{media_id}?token={token}"
# This URL supports chunked streaming
# First chunk arrives in ~300ms
// Initiate streaming TTS
async function streamAudio(text) {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_meklc281",
text: text,
outputFormat: "MP3_22050_128"
})
});
const { mediaId, token } = await response.json();
const streamUrl = `https://api.upliftai.org/v1/synthesis/stream-audio/${mediaId}?token=${token}`;
// Create audio element that starts streaming
const audio = new Audio(streamUrl);
audio.play(); // Starts playing as chunks arrive
return audio;
}
curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔",
"voiceId": "v_meklc281",
"phraseReplacementConfigId": "<string>"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'text' => 'سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔',
'voiceId' => 'v_meklc281',
'phraseReplacementConfigId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async"
payload := strings.NewReader("{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upliftai.org/v1/synthesis/text-to-speech/stream-async")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔\",\n \"voiceId\": \"v_meklc281\",\n \"phraseReplacementConfigId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"mediaId": "media_abc123xyz",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}{
"message": "Invalid request parameters"
}{
"message": "Rate limit exceeded, please try again later"
}Authorizations
API key with format "Bearer sk_api_..."
Body
Request for asynchronous streaming text-to-speech synthesis
The text to synthesize
2500"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔"
Format of the output audio. Wav files are usually 10x larger, we recommend using MP3 for best compression results while maintaining quality.
PCM_22050_16, WAV_22050_16, WAV_22050_32, MP3_22050_32, MP3_22050_64, MP3_22050_128, ULAW_8000_8 Identifier for the voice to use. Named voices: v_meklc281 (Urdu female), v_8eelc901 (Info/Edu), v_kwmp7zxt (Gen Z), v_yypgzenx (Dada Jee), v_30s70t3a (Nostalgic News)
"v_meklc281"
Optional ID of a phrase replacement configuration to apply
Response
Successfully initiated streaming synthesis
