Documentazione API
Integra il text-to-speech nelle tue applicazioni con la nostra API REST. Accedi a 7 motori TTS, oltre 250 voci e alla clonazione vocale.
Funzionalità API
- ✓ 7 motori TTS
- ✓ Oltre 250 voci
- ✓ Clonazione vocale
- ✓ 40+ lingue
- ✓ MP3, WAV, OGG
Indice
URL di base
https://api.texttospeechai.com/v1/
Autenticazione
Tutte le richieste API richiedono un token Bearer nell'header Authorization.
Come ottenere il tuo token API
- Accedi al tuo dashboard dell'account
- Vai alle impostazioni API
- Genera un nuovo token API
Header della richiesta
Authorization: Bearer YOUR_API_TOKEN
Esempio (cURL)
curl -X GET "https://api.texttospeechai.com/v1/account/" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Limiti di frequenza
Le richieste API sono limitate in base al livello del tuo account:
| Livello | Requests/Day |
|---|---|
| Gratis | 100 |
| Premium | 1,000 |
| Enterprise | 10,000 |
I limiti di frequenza vengono reimpostati a mezzanotte UTC. Controlla gli X-RateLimit-* header nelle risposte API.
Genera parlato
Crea una nuova richiesta di generazione text-to-speech.
/v1/generate/
Corpo della richiesta
| Parametro | Tipo | Obbligatorio | Descrizione |
|---|---|---|---|
text |
string | Sì | Testo da sintetizzare (max 5000 caratteri) |
voice |
string | Sì | Slug della voce (ad es. "en_US-kristin-medium") |
speed |
float | No | Velocità di parlato 0.5-2.0 (predefinito 1.0) |
pitch |
float | No | Regolazione dell'intonazione 0.5-2.0 (predefinito 1.0) |
format |
string | No | Formato di output: mp3, wav, ogg (predefinito mp3) |
Richiesta di esempio
curl -X POST "https://api.texttospeechai.com/v1/generate/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, welcome to TextToSpeechAI!",
"voice": "en_US-kristin-medium",
"speed": 1.0,
"format": "mp3"
}'
Risposta
{
"uuid": "abc123-def456-...",
"status": "pending",
"text_length": 35,
"voice": "en_US-kristin-medium",
"credits_used": 0.35,
"estimated_time": 5
}
Elenca le voci
Ottiene le voci disponibili con filtri facoltativi.
/v1/voices/
Parametri di query
| Parametro | Descrizione |
|---|---|
language |
Filtra per codice lingua (ad es. "en") |
gender |
Filtra per genere (maschile/femminile/neutro) |
model_type |
Filtra per motore TTS (piper, vits, bark, styletts2, tortoise) |
page |
Numero di pagina (predefinito 1) |
per_page |
Risultati per pagina (predefinito 50, max 100) |
Richiesta di esempio
curl "https://api.texttospeechai.com/v1/voices/?language=en&gender=female" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Controlla stato
Controlla lo stato di una richiesta di generazione.
/v1/status/{uuid}/
Valori di stato
pending- Richiesta messa in coda per l'elaborazioneprocessing- Generazione audio in corsocompleted- Audio pronto per il downloadfailed- Generazione non riuscita (vedi il campo error)
Risposta (completata)
{
"uuid": "abc123-def456-...",
"status": "completed",
"audio_url": "https://texttospeechai.com/uploads/generations/...",
"duration_seconds": 2.5,
"processing_time_ms": 1200
}
Clonazione vocale
Crea una voce clonata da un audio di riferimento.
/v1/clone/
Richiesta (multipart/form-data)
| Parametro | Tipo | Obbligatorio | Descrizione |
|---|---|---|---|
name |
string | Sì | Nome per la voce clonata |
audio |
file | Sì | Audio di riferimento (WAV/MP3, 6-60 secondi) |
language |
string | No | Codice lingua (predefinito "en") |
Richiesta di esempio
curl -X POST "https://api.texttospeechai.com/v1/clone/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "name=My Custom Voice" \
-F "audio=@reference.wav" \
-F "language=en"
Info account
Ottiene le informazioni sull'account e il saldo dei crediti.
/v1/account/
Risposta
{
"email": "user@example.com",
"credits": 1000.00,
"created_at": "2024-01-01T00:00:00Z",
"rate_limit": {
"limit": 100,
"remaining": 95,
"used": 5,
"resets_at": "2024-01-02T00:00:00Z"
}
}
Codici di errore
| Codice | Descrizione |
|---|---|
400 |
Bad Request: parametri non validi |
401 |
Unauthorized: token API non valido o mancante |
402 |
Payment Required: crediti insufficienti |
404 |
Not Found: risorsa non trovata |
429 |
Too Many Requests: limite di frequenza superato |
500 |
Errore interno del server |
Formato della risposta di errore
{
"error": "error_description"
}
Domande frequenti
/v1/clone/ endpoint. Creeremo una voce clonata che potrai usare nelle generazioni future. Le voci clonate funzionano in più lingue: clona una volta, genera in qualsiasi lingua supportata.
format parametro. Per l'input della clonazione vocale accettiamo audio di riferimento WAV e MP3.
Esempi di codice
import requests
import time
API_KEY = "YOUR_API_TOKEN"
BASE_URL = "https://api.texttospeechai.com/v1"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Generate speech
response = requests.post(
f"{BASE_URL}/generate/",
headers=headers,
json={
"text": "Hello, world!",
"voice": "en_US-kristin-medium",
"format": "mp3"
}
)
data = response.json()
uuid = data["uuid"]
# Poll for completion
while True:
status = requests.get(
f"{BASE_URL}/status/{uuid}/",
headers=headers
).json()
if status["status"] == "completed":
print(f"Audio URL: {status['audio_url']}")
break
elif status["status"] == "failed":
print(f"Error: {status['error']}")
break
time.sleep(2)
const API_KEY = 'YOUR_API_TOKEN';
const BASE_URL = 'https://api.texttospeechai.com/v1';
async function generateSpeech(text, voice) {
const response = await fetch(`${BASE_URL}/generate/`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: text,
voice: voice,
format: 'mp3'
})
});
const data = await response.json();
// Poll for completion
while (true) {
const status = await fetch(
`${BASE_URL}/status/${data.uuid}/`,
{ headers: { 'Authorization': `Bearer ${API_KEY}` } }
).then(r => r.json());
if (status.status === 'completed') {
return status.audio_url;
} else if (status.status === 'failed') {
throw new Error(status.error);
}
await new Promise(r => setTimeout(r, 2000));
}
}
// Usage
generateSpeech('Hello, world!', 'en_US-kristin-medium')
.then(url => console.log('Audio URL:', url))
.catch(err => console.error(err));
# Generate speech
curl -X POST "https://api.texttospeechai.com/v1/generate/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Hello, world!", "voice": "en_US-kristin-medium"}'
# Check status (replace UUID)
curl "https://api.texttospeechai.com/v1/status/abc123-def456/" \
-H "Authorization: Bearer YOUR_API_TOKEN"
# List voices
curl "https://api.texttospeechai.com/v1/voices/?language=en" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Pronto a costruire?
Ottieni la tua chiave API gratuita e inizia a generare il parlato in pochi minuti. 1,000 crediti gratuiti inclusi.
Crea account gratuitoNessuna carta di credito richiesta. 100 richieste API/giorno gratuite.