Async Text to Speech - Uplift AI API Docs

Async TTS with retrieval

Python

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

Response Codes

Sample Responses

{
  "mediaId": "media_abc123xyz",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
{
  "message": "Invalid request parameters"
}
{
  "message": "Rate limit exceeded, please try again later"
}

Authorizations

Authorization: string, header, required

Request Body

Content-Type: application/json

Required Fields

Sample Response

{
  "mediaId": "media_abc123xyz",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}