Google Text-to-Speech
Teks-ke-suara neural Google dengan suara WaveNet. Lebih dari 380 suara dalam 50+ bahasa dengan dukungan SSML.
✓ 380+ suara
✓ 50+ bahasa
✓ Kualitas WaveNet
✓ Dukungan SSML
Autentikasi
Untuk mengakses Google TTS melalui API Doitong, gunakan kunci API Doitong Anda. Sertakan kunci tersebut dalam mutasi GraphQL atau header REST API.
// GraphQL Header
{
"Authorization": "Bearer YOUR_API_KEY"
}
// REST Header
"X-API-Key": "YOUR_API_KEY"
Memulai Cepat
Mulai gunakan Google TTS API hanya dalam beberapa menit. Ikuti langkah-langkah sederhana ini untuk membuat tts pertama Anda.
Langkah 1: Dapatkan Kunci API Anda
Daftar akun Doitong dan buka dasbor Anda untuk membuat kunci API.
Langkah 2: Buat Permintaan Pertama Anda
Gunakan salah satu contoh kode di bawah ini untuk melakukan panggilan API pertama Anda.
curl -X POST https://api.doitong.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"query": "mutation Generate($input: GenerateInput!) { generate(input: $input) { id status type provider url metadata creditCost } }",
"variables": {
"input": {
"type": "AUDIO",
"provider": "google-tts",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0
}
}
}
}'
const response = await fetch('https://api.doitong.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
query: `
mutation GenerateSpeech($input: TTSInput!) {
generateSpeech(input: $input) {
id
audioUrl
duration
}
}
`,
variables: {
input: {
service: 'google-tts',
text: 'Hello world, this is a text to speech example.',
voice: 'en-US-neural',
speed: 1.0
}
}
})
});
const data = await response.json();
console.log('Result:', data.data.generate);
import requests
import json
url = "https://api.doitong.com/graphql"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
query = """
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
}
}
"""
variables = {
"input": {
"type": "AUDIO",
"provider": "google-tts",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0
}
}
}
response = requests.post(url, json={
"query": query,
"variables": variables
}, headers=headers)
data = response.json()
print("Result:", data["data"]["generate"])
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
createdAt
}
}
# Variables
{
"input": {
"type": "AUDIO",
"provider": "google-tts",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0,
"pitch": 1.0,
"language": "en",
"version": "neural2"
}
}
}
Harga
Google TTS API menggunakan model harga berbasis kredit. Kredit digunakan berdasarkan kompleksitas dan durasi konten yang dihasilkan.
| Fitur | Kredit | Deskripsi |
|---|---|---|
| Suara Standar | 1 kredit per 100 karakter | Suara neural dasar |
| Suara Premium | 2 kredit per 100 karakter | Suara neural canggih dengan emosi |
Endpoint API
Google TTS API tersedia melalui endpoint GraphQL terpadu kami.
Endpoint GraphQL
POST https://api.doitong.com/graphql
Endpoint REST
POST https://api.doitong.com/v1/tts
Parameter
Parameter yang tersedia untuk permintaan Google TTS API:
| Parameter | Tipe | Wajib | Deskripsi |
|---|---|---|---|
service |
String | Yes | Pengidentifikasi layanan: "google-tts" |
version |
String | No | Model version: "wavenet", "neural2" |
webhookUrl |
String | No | URL untuk menerima notifikasi penyelesaian |
Format Respons
Semua respons API mengikuti format yang konsisten:
Respons Berhasil
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "processing",
"url": null,
"webhookUrl": "https://your-webhook.com/callback",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Respons Selesai
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
"duration": null,
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Penanganan Error
API menggunakan kode status HTTP standar dan mengembalikan pesan error yang mendetail.
Kode Error Umum
| Kode Status | Tipe Error | Deskripsi |
|---|---|---|
| 400 | Bad Request | Invalid parameters or malformed request |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient credits |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server error, please retry |
Format Respons Error
{
"errors": [
{
"message": "Insufficient credits for this operation",
"extensions": {
"code": "INSUFFICIENT_CREDITS",
"creditsRequired": 100,
"creditsAvailable": 50
}
}
]
}
Webhook
Terima notifikasi real-time saat pembuatan tts Anda selesai.
Menyiapkan Webhook
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
Payload Webhook
{
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
"service": "google-tts",
"createdAt": "2024-01-01T00:00:00Z",
"completedAt": "2024-01-01T00:01:00Z",
"metadata": {
"duration": null,
"width": null,
"height": null
}
}
Keamanan Webhook
Semua permintaan webhook menyertakan header tanda tangan untuk verifikasi:
X-Doitong-Signature: sha256=abc123...
Batas Kecepatan
Untuk memastikan penggunaan yang adil dan stabilitas sistem, batas kecepatan berikut berlaku:
| Paket | Permintaan/Menit | Pekerjaan Simultan | Batas Harian |
|---|---|---|---|
| Gratis | 10 | 1 | 100 |
| Starter | 30 | 3 | 1,000 |
| Pro | 60 | 10 | 10,000 |
| Enterprise | Kustom | Kustom | Tanpa Batas |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
Praktik Terbaik
1. Optimalkan Prompt Anda
Tulis prompt yang jelas dan deskriptif untuk hasil terbaik:
- Be specific about visual elements, style, and mood
- Include details about lighting, camera angles, and composition
- Avoid contradictory or impossible requests
2. Tangani Pemrosesan Asinkron
Pembuatan bersifat asinkron. Terapkan polling atau webhook yang tepat:
// Polling example
async function pollStatus(jobId) {
let status = 'processing';
while (status === 'processing') {
await sleep(2000); // Wait 2 seconds
const result = await checkJobStatus(jobId);
status = result.status;
}
return result;
}
3. Pemulihan Error
Terapkan logika percobaan ulang (retry) dengan exponential backoff:
async function retryWithBackoff(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await sleep(Math.pow(2, i) * 1000);
}
}
}
4. Pantau Penggunaan Kredit
Lacak konsumsi kredit Anda untuk menghindari gangguan:
- Check credit balance before large batch operations
- Set up alerts for low credit thresholds
- Implement credit-aware request queuing
Siap untuk Memulai?
Bergabunglah dengan ribuan pengembang yang menggunakan Google TTS API untuk membuat konten luar biasa