Text-to-Speech API
API Description
The text-to-speech synthesis API.
Request Description
URL
https://openapi.sys303.com/api/cognitive/tts/stream
Parameters
Header Parameters
| Parameter | Value |
|---|---|
| Content-Type | application/json |
| X-Secret | Get it here |
Body Parameters
| Parameter | Required | Type | Possible Values | Description |
|---|---|---|---|---|
| lang | Yes | int | [0, 1, 4, 5] | 0: Tibetan (Ü-Tsang), 1: Chinese, 4: Tibetan (Khampa), 5: Tibetan (Amdo) |
| vcn | No | string | ["xiaoxiao", "yunjian"] | When lang is 1, optional; choose "xiaoxiao" or "yunjian". For other lang values, pass an empty string. |
| inputText | Yes | string | - | Text for speech synthesis [Unicode, max 3000 characters] |
Request Example
- bash
- python
- C#
- Java
curl https://openapi.sys303.com/api/cognitive/tts/stream \
--request POST \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'X-Secret: {X-Secret}' \
--data '{
"lang": 0,
"inputText": "Text for speech synthesis",
"vcn": ""
}' \
--output out.pcm
import requests
url = "https://openapi.sys303.com/api/cognitive/tts/stream"
headers = {
"Accept": "*/*",
"Content-Type": "application/json",
"X-Secret": "{your X-Secret}"
}
data = {
"lang": 0,
"inputText": "Text for speech synthesis",
"vcn": ""
}
resp = requests.post(url, headers=headers, json=data, stream=True)
if resp.status_code == 200:
with open("out.pcm", "wb") as f:
for chunk in resp.iter_content(chunk_size=4096):
if chunk:
f.write(chunk)
print("Saved successfully: out.pcm")
else:
print("Request failed")
print(resp.text)
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.IO;
class Program
{
static async Task Main()
{
var url = "https://openapi.sys303.com/api/cognitive/tts/stream";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "*/*");
client.DefaultRequestHeaders.Add("X-Secret", "{your X-Secret}");
var json = @"{
""lang"": 0,
""inputText"": ""Text for speech synthesis"",
""vcn"": """"
}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var bytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("out.pcm", bytes);
Console.WriteLine("Saved successfully: out.pcm");
}
else
{
var err = await response.Content.ReadAsStringAsync();
Console.WriteLine("Request failed: " + err);
}
}
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
public class TtsDemo {
public static void main(String[] args) throws Exception {
String json = """
{
"lang": 0,
"inputText": "Text for speech synthesis",
"vcn": ""
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://openapi.sys303.com/api/cognitive/tts/stream"))
.header("Accept", "*/*")
.header("Content-Type", "application/json")
.header("X-Secret", "{your X-Secret}")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<Path> response = client.send(
request,
HttpResponse.BodyHandlers.ofFile(Path.of("out.pcm"))
);
System.out.println("HTTP status code: " + response.statusCode());
System.out.println("Saved: out.pcm");
}
}
Return Explanation
Successful Request
Returns a PCM audio stream. Sample rate 16000; mono channel.
You can verify playback with:
ffplay -f s16le -ar 16000 out.pcm
Error Response Parameter Description
| Field | Required | Type | Status | Description |
|---|---|---|---|---|
| traceId | Yes | String | - | Unique traceId for troubleshooting |
| msgId | Yes | String | - | Business status code |
| msg | Yes | String | Error description | |
| data | Yes | String | - | Null |
Return Example
Failure
Auth Failed:
{
"traceId": "0HNLN3J9DCJSE:00000001",
"msgId": "4011001",
"msg": "AuthFailed",
"data": null
}
Invalid request parameters:
{
"traceId": "0HNL06O44AU14:00000001",
"msgId": "500",
"msg": "Specified argument was out of the range of valid values. (Parameter 'lang')",
"data": null
}
Insufficient quota:
{
"traceId": "0HNL06O44AU1F:00000001",
"msgId": "2001001",
"msg": "InsufficientInventory",
"data": null
}
Input text too long:
{
"traceId": "0HNL06O44AUVB:00000001",
"msgId": "4004002",
"msg": "InputTooLong",
"data": null
}