Generate Text-to-Speech Audio
curl --request POST \
--url https://api.sunbird.ai/tasks/modal/tts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"response_mode": "url",
"speaker_id": 248,
"text": "I am a nurse who takes care of many people."
}
'import requests
url = "https://api.sunbird.ai/tasks/modal/tts"
payload = {
"response_mode": "url",
"speaker_id": 248,
"text": "I am a nurse who takes care of many people."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
response_mode: 'url',
speaker_id: 248,
text: 'I am a nurse who takes care of many people.'
})
};
fetch('https://api.sunbird.ai/tasks/modal/tts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sunbird.ai/tasks/modal/tts",
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([
'response_mode' => 'url',
'speaker_id' => 248,
'text' => 'I am a nurse who takes care of many people.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.sunbird.ai/tasks/modal/tts"
payload := strings.NewReader("{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.sunbird.ai/tasks/modal/tts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sunbird.ai/tasks/modal/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"audio_url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"duration_estimate_seconds": 123,
"text_length": 123,
"speaker_id": 241,
"speaker_name": "<string>"
}{
"error": "<string>",
"success": false,
"detail": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}{
"error": "<string>",
"success": false,
"detail": "<string>"
}Legacy Text to Speech
Generate TTS Audio (Modal)
deprecated
Convert text to speech and return a signed URL to the audio file.
POST
/
tasks
/
modal
/
tts
Generate Text-to-Speech Audio
curl --request POST \
--url https://api.sunbird.ai/tasks/modal/tts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"response_mode": "url",
"speaker_id": 248,
"text": "I am a nurse who takes care of many people."
}
'import requests
url = "https://api.sunbird.ai/tasks/modal/tts"
payload = {
"response_mode": "url",
"speaker_id": 248,
"text": "I am a nurse who takes care of many people."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
response_mode: 'url',
speaker_id: 248,
text: 'I am a nurse who takes care of many people.'
})
};
fetch('https://api.sunbird.ai/tasks/modal/tts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sunbird.ai/tasks/modal/tts",
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([
'response_mode' => 'url',
'speaker_id' => 248,
'text' => 'I am a nurse who takes care of many people.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.sunbird.ai/tasks/modal/tts"
payload := strings.NewReader("{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.sunbird.ai/tasks/modal/tts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sunbird.ai/tasks/modal/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"response_mode\": \"url\",\n \"speaker_id\": 248,\n \"text\": \"I am a nurse who takes care of many people.\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"audio_url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"duration_estimate_seconds": 123,
"text_length": 123,
"speaker_id": 241,
"speaker_name": "<string>"
}{
"error": "<string>",
"success": false,
"detail": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}{
"error": "<string>",
"success": false,
"detail": "<string>"
}Authorizations
The access token received from the authorization server in the OAuth 2.0 flow.
Body
application/json
Request model for TTS generation.
Text to convert to speech
Required string length:
1 - 10000Example:
"Hello, this is a text-to-speech test."
Speaker voice for TTS generation
Available options:
241, 242, 243, 245, 246, 248 Examples:
248
246
How to return the audio: 'url' for signed URL, 'stream' for streaming, 'both' for streaming with final URL
Available options:
url, stream, both Response
Audio generated successfully
Response model for TTS generation (URL mode).
Whether the request was successful
Signed URL to access the audio file
When the signed URL expires
Name of the audio file in storage
Estimated audio duration in seconds
Length of the input text
Speaker voice used for generation
Available options:
241, 242, 243, 245, 246, 248 Human-readable speaker name

