Stream Text to Speech - Uplift AI API Docs
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stream text to speech Example JS
JavaScript
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 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
Authorizations
Authorization
- Type: string
- Location: header
- Required: API key with format "Bearer sk_api_..."
Body
- application/json
- Request for streaming text-to-speech synthesis
- voiceId: string (required) - Identifier for the voice to use. Options include
v_8eelc901,v_kwmp7zxt,v_yypgzenx,v_30s70t3a - text: string (required) - The text to synthesize (Maximum string length: 2500)
- outputFormat: enum
(required) - Format of the output audio. Available options: PCM_22050_16,WAV_22050_16,WAV_22050_32,MP3_22050_32,MP3_22050_64,MP3_22050_128,ULAW_8000_8 - phraseReplacementConfigId: string (optional) - ID of a phrase replacement configuration to apply
- voiceId: string (required) - Identifier for the voice to use. Options include
Response
- 200: successful audio synthesis
- 400: bad request
- 429: rate limit exceeded, please try again later
{"message": "<string>"}
{
"message": "Rate limit exceeded, please try again later"
}