import requests
import json
# Step 1: Initiate async TTS
url = "https://api.upliftai.org/v1/synthesis/text-to-speech-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: Retrieve audio when ready
media_id = result['mediaId']
token = result['token']
audio_url = f"https://api.upliftai.org/v1/synthesis/stream-audio/{media_id}?token={token}"
# Get the audio
audio_response = requests.get(audio_url)
# Save to file
with open('output.mp3', 'wb') as f:
f.write(audio_response.content)// Server-side: Initiate TTS
async function initiateTTS() {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech-async', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_meklc281",
text: "سلام، یہ پاکستان کی تاریخ کے بارے میں ہے۔",
outputFormat: "MP3_22050_128"
})
});
const { mediaId, token } = await response.json();
// Send URL to client or webhook
const audioUrl = `https://api.upliftai.org/v1/synthesis/stream-audio/${mediaId}?token=${token}`;
// Client can now fetch audio directly
return audioUrl;
}
curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech-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-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-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-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-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 Text to Speech
This endpoint initiates text-to-speech synthesis and immediately returns a mediaId and token. The audio is generated asynchronously and can be retrieved using the returned credentials.
When to use this endpoint:
- Bot integrations (WhatsApp, Telegram, etc.) - Avoid audio passing through your system
- Webhook workflows - When you need to process audio generation separately
- Batch processing - When converting multiple texts without blocking
- Direct client delivery - Let clients fetch audio directly using the secure token
For best results with Urdu, use Urdu script. For English words within Urdu text, use ASCII characters. Example: “یہ ایک exerted force ہے”
The generated audio URL can be shared directly with end users or services without proxying through your server.
import requests
import json
# Step 1: Initiate async TTS
url = "https://api.upliftai.org/v1/synthesis/text-to-speech-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: Retrieve audio when ready
media_id = result['mediaId']
token = result['token']
audio_url = f"https://api.upliftai.org/v1/synthesis/stream-audio/{media_id}?token={token}"
# Get the audio
audio_response = requests.get(audio_url)
# Save to file
with open('output.mp3', 'wb') as f:
f.write(audio_response.content)// Server-side: Initiate TTS
async function initiateTTS() {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech-async', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_meklc281",
text: "سلام، یہ پاکستان کی تاریخ کے بارے میں ہے۔",
outputFormat: "MP3_22050_128"
})
});
const { mediaId, token } = await response.json();
// Send URL to client or webhook
const audioUrl = `https://api.upliftai.org/v1/synthesis/stream-audio/${mediaId}?token=${token}`;
// Client can now fetch audio directly
return audioUrl;
}
curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech-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-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-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-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-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 text-to-speech synthesis
The text to synthesize
2500"سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔"
Format of the output audio. Wav files are usually 10x larger, we recommend using MP3 or OGG 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, OGG_22050_16, 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 audio synthesis
