Skip to main content

🗣️ iApp Text-to-Speech (TTS) [Version 3 Alpha]

🗣️ แปลงข้อความเป็นเสียง [Version 3.0.0 Alpha]

Version Status New Production Production Production Legacy Legacy Legacy

Welcome to iApp TTS version 3 API, a cutting-edge text-to-speech synthesis service that converts text into natural-sounding speech. Our API uses an advanced AI model to generate audio from text input with excellent accuracy and speed.

Try Demo

Getting Started

Prerequisites

  • Text input in Thai language
  • Maximum tokens: 1400
  • Output format: WAV

Quick Start

  • Fast processing with GPU acceleration
  • Natural speech generation
  • High-quality speech output

Key Features

  • Natural speech synthesis using state-of-the-art AI
  • Advanced voice quality tuning via parameters
  • High-speed response times
  • Simple REST API interface

API Endpoints

EndpointMethodDescriptionCost
/v3/store/speech/text-to-speech
Legacy: /v3/audio/
POSTConvert Thai/English text to natural speech1 IC per 30 seconds
Legacy: /v3/audio/ttsvc/enPOSTLegacy TTS endpoint1 IC per 30 seconds

API Usage

Endpoints

  • POST /tts - Generate speech from text and download as a file

API Request Examples

Using cURL:

# Health check
curl https://api.iapp.co.th/v3/audio/health

# Generate speech and save to file
curl -X POST https://api.iapp.co.th/v3/audio/tts \
-H "Content-Type: application/json" \
-d '{"text":"Hello, this is a test.","temperature":0.2,"top_p":0.95}' \
--output test.wav

Using Python:

import requests

# Text-to-speech request
response = requests.post(
"https://api.iapp.co.th/v3/audio/tts",
json={
"text": "สวัสดีครับ",
"temperature": 0.2,
"top_p": 0.95,
"max_new_tokens": 1400
}
)

# Save the audio response to a file
with open("output.wav", "wb") as f:
f.write(response.content)

Request Parameters

ParameterTypeDescriptionDefault
textstringText to convert to speechRequired
temperaturefloatGeneration temperature (higher = more random)0.2
top_pfloatTop-p sampling parameter0.95
max_new_tokensintegerMaximum number of tokens to generate1400

Best Practices

  • Use proper punctuation for better speech synthesis
  • Keep sentences natural and conversational
  • For long text, consider breaking it into smaller segments
  • Adjust temperature and top_p parameters to control voice style:
    • Lower temperature (0.1-0.5): More consistent, stable voice
    • Higher temperature (0.6-1.0): More expressive but less predictable

Code Examples

Curl

curl -X POST https://prod-api.iapp.co.th/v3/store/speech/text-to-speech \
-H "apikey: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "สวัสดีครับ", "temperature": 0.2, "top_p": 0.95, "max_new_tokens": 1400}' \
--output output.wav

Python

import requests

url = "https://prod-api.iapp.co.th/v3/store/speech/text-to-speech"
headers = {
"apikey": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"text": "สวัสดีครับ",
"temperature": 0.2,
"top_p": 0.95,
"max_new_tokens": 1400
}

response = requests.post(url, headers=headers, json=data)

# Save the audio response to a file
with open("output.wav", "wb") as f:
f.write(response.content)

JavaScript

const axios = require("axios");
const fs = require("fs");

const config = {
method: "post",
url: "https://prod-api.iapp.co.th/v3/store/speech/text-to-speech",
headers: {
apikey: "YOUR_API_KEY",
"Content-Type": "application/json",
},
data: {
text: "สวัสดีครับ",
temperature: 0.2,
top_p: 0.95,
max_new_tokens: 1400
},
responseType: "arraybuffer"
};

axios(config)
.then((response) => {
fs.writeFileSync("output.wav", response.data);
console.log("Audio saved to output.wav");
})
.catch((error) => console.log(error));

PHP

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://prod-api.iapp.co.th/v3/store/speech/text-to-speech',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode([
'text' => 'สวัสดีครับ',
'temperature' => 0.2,
'top_p' => 0.95,
'max_new_tokens' => 1400
]),
CURLOPT_HTTPHEADER => array(
'apikey: YOUR_API_KEY',
'Content-Type: application/json'
),
));

$response = curl_exec($curl);
curl_close($curl);

// Save audio to file
file_put_contents('output.wav', $response);
?>

Swift

import Foundation

let url = URL(string: "https://prod-api.iapp.co.th/v3/store/speech/text-to-speech")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("YOUR_API_KEY", forHTTPHeaderField: "apikey")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

let jsonData = try! JSONSerialization.data(withJSONObject: [
"text": "สวัสดีครับ",
"temperature": 0.2,
"top_p": 0.95,
"max_new_tokens": 1400
])
request.httpBody = jsonData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
// Save audio to file
try? data.write(to: URL(fileURLWithPath: "output.wav"))
print("Audio saved to output.wav")
}
}
task.resume()

Kotlin

import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File

val client = OkHttpClient()

val json = """
{
"text": "สวัสดีครับ",
"temperature": 0.2,
"top_p": 0.95,
"max_new_tokens": 1400
}
""".trimIndent()

val requestBody = json.toRequestBody("application/json".toMediaTypeOrNull())

val request = Request.Builder()
.url("https://prod-api.iapp.co.th/v3/store/speech/text-to-speech")
.addHeader("apikey", "YOUR_API_KEY")
.post(requestBody)
.build()

client.newCall(request).execute().use { response ->
response.body?.bytes()?.let { bytes ->
File("output.wav").writeBytes(bytes)
println("Audio saved to output.wav")
}
}

Java

import okhttp3.*;
import java.io.FileOutputStream;
import java.io.IOException;

OkHttpClient client = new OkHttpClient();

String json = "{\"text\": \"สวัสดีครับ\", \"temperature\": 0.2, \"top_p\": 0.95, \"max_new_tokens\": 1400}";

RequestBody body = RequestBody.create(
MediaType.parse("application/json"),
json
);

Request request = new Request.Builder()
.url("https://prod-api.iapp.co.th/v3/store/speech/text-to-speech")
.addHeader("apikey", "YOUR_API_KEY")
.post(body)
.build();

try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful() && response.body() != null) {
byte[] audioBytes = response.body().bytes();
try (FileOutputStream fos = new FileOutputStream("output.wav")) {
fos.write(audioBytes);
System.out.println("Audio saved to output.wav");
}
}
} catch (IOException e) {
e.printStackTrace();
}

Dart

import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:io';

var headers = {
'apikey': 'YOUR_API_KEY',
'Content-Type': 'application/json'
};

var data = {
"text": "สวัสดีครับ",
"temperature": 0.2,
"top_p": 0.95,
"max_new_tokens": 1400
};

var response = await http.post(
Uri.parse('https://prod-api.iapp.co.th/v3/store/speech/text-to-speech'),
headers: headers,
body: jsonEncode(data)
);

// Save audio to file
await File('output.wav').writeAsBytes(response.bodyBytes);
print('Audio saved to output.wav');