async function streamTextToSpeech() {
try {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech/stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_8eelc901",
text: "سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔",
outputFormat: "MP3_22050_128"
})
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Get the reader from the stream
const reader = response.body.getReader();
// Process each chunk as it arrives
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
// Process each chunk
// you can stream this audio to your to your clients etc.
}
} catch (error) {
console.error('Error:', error);
}
}curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech/stream \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"phraseReplacementConfigId": "<string>"
}
'import requests
url = "https://api.upliftai.org/v1/synthesis/text-to-speech/stream"
payload = {
"text": "<string>",
"phraseReplacementConfigId": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.upliftai.org/v1/synthesis/text-to-speech/stream",
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' => '<string>',
'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"
payload := strings.NewReader("{\n \"text\": \"<string>\",\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")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upliftai.org/v1/synthesis/text-to-speech/stream")
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\": \"<string>\",\n \"phraseReplacementConfigId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body"<string>"{
"message": "<string>"
}{
"message": "Rate limit exceeded, please try again later"
}Stream Text to Speech
Converts the provided text to speech audio using the specified voice, response is streamed with “Transfer-Encoding” “chunked” header. We currently aim the p90 first chunk latency to be around 300ms in Pakistan, we are also actively working reducing this.
For best results, we expect you to use Urdu script. To get better pronounciation of English words, use ASCII characters for them. Example “یہ ایک exerted force ہے”
Returns the audio data directly in the response.
async function streamTextToSpeech() {
try {
const response = await fetch('https://api.upliftai.org/v1/synthesis/text-to-speech/stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
voiceId: "v_8eelc901",
text: "سلام، آپ اِس وقت اوریٹر کی آواز سن رہے ہیں۔",
outputFormat: "MP3_22050_128"
})
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Get the reader from the stream
const reader = response.body.getReader();
// Process each chunk as it arrives
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
// Process each chunk
// you can stream this audio to your to your clients etc.
}
} catch (error) {
console.error('Error:', error);
}
}curl --request POST \
--url https://api.upliftai.org/v1/synthesis/text-to-speech/stream \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"phraseReplacementConfigId": "<string>"
}
'import requests
url = "https://api.upliftai.org/v1/synthesis/text-to-speech/stream"
payload = {
"text": "<string>",
"phraseReplacementConfigId": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.upliftai.org/v1/synthesis/text-to-speech/stream",
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' => '<string>',
'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"
payload := strings.NewReader("{\n \"text\": \"<string>\",\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")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"phraseReplacementConfigId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.upliftai.org/v1/synthesis/text-to-speech/stream")
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\": \"<string>\",\n \"phraseReplacementConfigId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body"<string>"{
"message": "<string>"
}{
"message": "Rate limit exceeded, please try again later"
}Authorizations
API key with format "Bearer sk_api_..."
Body
Request for streaming text-to-speech synthesis
Identifier for the voice to use. Options include v_8eelc901 (Info/Edu), v_kwmp7zxt (Gen Z), v_yypgzenx (Dada Jee), v_30s70t3a (Nostalgic News)
v_8eelc901, v_kwmp7zxt, v_yypgzenx, v_30s70t3a The text to synthesize
2500Format 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 Optional ID of a phrase replacement configuration to apply
Response
Successful audio synthesis
The response is of type file.
