Dogfennaeth API

Cyfuno TTS.ai â'ch rhaglenni gyda'n API REST. Fformat cydnaws â OpenAI ar gyfer symud hawdd.

API REST Cydnaws OpenAI Ymateb JSON Cynhaliaeth Llif

Crynodeb

Mae'r API TTS.ai yn darparu mynediad rhaglennu i bob nodweddion y platfform: cyfansoddiad testun-i-ganu, trosysgrifiad siarad-i-testun, clonio llais, gwella sain, a mwy. Mae'r API yn defnyddio cytundebau REST safonol gyda chorff cais/ateb JSON.

Allwedd API

Nôl eich allwedd API o Gosodiadau Cyfrif. Ar gael ar gynlluniau Pro ac Enterprise.

URL Sail

https://api.tts.ai/v1/

Awdurdodi

Tocyn porthwr drwy Authorization pennawd

Dilysiant

Haen rydd — dim angen allwedd. Postio Di-enw i /v1/tts/ gweithio heb unrhyw awdurdodiad, hyd at 5,000 o nodau/diwrnod am bob IP, gan ddefnyddio unrhyw un o'n modelau am ddim (piper, vits, melotts, kokoro). Cofrestru ar gyfer cyfrif am ddim i gael 15,000 o nodau bonws a mynediad i fathau premiwm.

Mae angen dilysiant ar bob cais API drwy tocyn Bearer yn y Authorization pennawd.

Pennawd HTTP
Authorization: Bearer sk-tts-your-api-key-here
Cadw eich allwedd API yn gyfrinachol. Peidiwch â'i rannu mewn cod ar ochr y cleient, storfeydd cyhoeddus, neu gofnodion. Cylchdroi allweddi'n rheolaidd o'ch gosodiadau cyfrif.

SDKs

Mae SDKs swyddogol yn gwneud hi'n hawdd i gyd-fynd TTS.ai â'ch rhaglen. Mae'r ddau yn ffynhonnell agored ac ar gael ar GitHub.

Python

pip install ttsai
from tts_ai import TTSClient

client = TTSClient(api_key="sk-tts-...")
audio = client.generate(
    text="Hello world!",
    model="kokoro"
)
client.save(audio, "output.wav")
GitHub

JavaScript / Node.js

npm install @ttsainpm/ttsai
const { TTSClient } = require('@ttsainpm/ttsai');

const client = new TTSClient({
  apiKey: 'sk-tts-...'
});
const audio = await client.generate({
  input: 'Hello world!',
  model: 'kokoro'
});
await client.saveToFile(audio, 'output.wav');
GitHub

URL Sail

URL Sail: https://api.tts.ai/v1/

Mae pob diwedd-bwynt yn gysylltiedig â'r LAU sylfaenol hwn. Er enghraifft, y diwedd-bwynt TTS yw:

POST https://api.tts.ai/v1/tts/

Terfynau Cyfradd

Mae terfynau cyflymder API yn amrywio yn ôl y cynllun:

Cynllun Cais/mun Cyfunol Uchafswm hyd testun
Rhydd 10 2 500 o nodau
Cychwynnydd 30 3 1,000,000 o nodau
Pro 60 5 1,000,000 o nodau
Enterprise 300 20 50,000 o nodau

Cynhwysir penawdau terfyn cyflymder mewn pob ymateb: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.

Costiau Credyd

Gwasanaeth Cost Uned
TTS (Modelau am ddim: Piper, VITS, MeloTTS) 1 credyd bob 1,000 o nodau
TTS (Modelau safonol: Kokoro, CosyVoice 2, ac ati) 2 credyd bob 1,000 o nodau
TTS (Modelau premiwm: Tortoise, Chatterbox, ac ati) 4 credyd bob 1,000 o nodau
Lleferydd i DestunName 2 credyd bob munud o sain
Clonio Llywio 4 credyd bob 1,000 o nodau
Newidydd LlygaidName 3 credyd bob munud o sain
Cynyddu Sain 2 credyd bob munud o sain
Gwaredu Cerdd / Gwahanu Cerdd 3-4 credyd bob munud o sain
Cyfieithiad LleferyddName 5 credyd bob munud o sain
Sgwrs LaisName 3 credyd bob tro
Canfod Bysellau & BPM Rhydd --
Trosiwr SainName Rhydd --

Testun i LeferyddComment

POST /v1/tts/

Trosi testun i sain siarad. Dychwelyd ffeil sain yn y fformat gofynnol.

Corff y Cais

ParamedrauMathAngenrheidiolDisgrifiad
model string & # 160; Na Dynodiad y model (e.e. kokoro, chatterbox, piper)
text string & # 160; IeQShortcut Testun i'w drosi i lais (uchafswm o 5,000 o nodau ar gyfer Pro, 50,000 ar gyfer Enterprise)
voice string & # 160; IeQShortcut Dynodiad llais (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael)
format string & # 160; Na Fformat allbwn: mp3 (rhagosodedig), wav, flac, ogg
speed float & # 160; Na Ffactor cyflymder siarad. Rhagosodedig: 1.0. Amrediad: 0.5 i 2.0
language string & # 160; Na Côd iaith (e.e. en, es). Yn cael ei ganfod yn awtomatig os gadewir allan.
instructions string & # 160; Na Cynghorion gweithredu/darpariaeth (≤500 o nodau). e.e. \
pronunciations object | array & # 160; Na Trosysgrifo ynganiad ar gais. naill ai {\
stream boolean & # 160; Na Galluogi ymateb llif. Rhagosodedig: false

Cais Enghreifftiol

cURL
curl -X POST https://api.tts.ai/v1/tts/ \
  -H "Authorization: Bearer sk-tts-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kokoro",
    "text": "Hello from TTS.ai! This is a test.",
    "voice": "af_bella",
    "format": "mp3"
  }' \
  --output output.mp3

Tags SSML

Amlapio rhifau, dyddiadau, arian, rhifau ffôn, a byrddau termau mewn

dehongli-felMewnbwnLlefaru fel
cardinal1234one thousand two hundred thirty-four
ordinal21twenty-first
date1999-12-31trigain- unfed o Ddiweddar, naw deg naw- naw
time14:30two thirty PM
telephone+1-555-867-5309plus one five five five eight six seven…
currency$1,234.56one thousand two hundred thirty-four dollars and fifty-six cents
spell-outNASAN A S A

Rhagosodiadau fformat dyddiad i mdy ar gyfer Saesneg a dmy ar gyfer eraill; trosglwyddo gyda format=\

Enghraifft
{
  "model": "kokoro",
  "voice": "af_bella",
  "text": "Your appointment is on <say-as interpret-as=\"date\">2026-04-26</say-as> at <say-as interpret-as=\"time\">14:30</say-as>. Please call <say-as interpret-as=\"telephone\">+1-555-867-5309</say-as> if you need to reschedule."
}

Ymateb

The TTS endpoint queues your request and returns a JSON response with a job UUID. You then poll for the result.

Step 1: Submit request

Response (JSON)
{
  "uuid": "77b71db532874ce98e84a69a2d740d4c",
  "job_id": "f21316bb-aefa-480d-8523-701d1e3184ce",
  "status": "queued",
  "credits_used": 11,
  "credits_remaining": 15000
}

Step 2: Poll for result

GET /v1/speech/results/?uuid=<job_uuid>

Poll this endpoint every 1-2 seconds until status is completed or failed.

Polling response (completed)
{
  "status": "completed",
  "result_url": "https://api.tts.ai/static/downloads/77b71db5.../output.mp3"
}
Polling response (still processing)
{
  "status": "processing"
}

Step 3: Download audio

Fetch the result_url from the completed response to download the audio file.

Enghraifft lawn

Python
import requests, time

API_KEY = "sk-tts-your-key"
BASE = "https://api.tts.ai"

# 1. Submit TTS request
resp = requests.post(f"{BASE}/v1/tts/", json={
    "model": "kokoro",
    "text": "Hello from TTS.ai!",
    "voice": "af_bella"
}, headers={"Authorization": f"Bearer {API_KEY}"})
data = resp.json()
uuid = data["uuid"]

# 2. Poll for result
while True:
    result = requests.get(f"{BASE}/v1/speech/results/",
        params={"uuid": uuid}).json()
    if result["status"] == "completed":
        # 3. Download audio
        audio = requests.get(result["result_url"])
        with open("output.mp3", "wb") as f:
            f.write(audio.content)
        break
    elif result["status"] == "failed":
        raise Exception(result.get("error", "Generation failed"))
    time.sleep(1.5)

Streaming alternative: For supported models (Kokoro, MeloTTS), use POST /v1/tts/stream/ for real-time Server-Sent Events (SSE) streaming — no polling needed.

Lleferydd i DestunName

POST /v1/stt/

Trawsnewid sain i destun. Cynhelir 99 iaith gyda darganfod awtomatig.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file & # 160; IeQShortcut Ffeil sain (MP3, WAV, FLAC, OGG, M4A, MP4, WebM). Uchafswm 100MB.
model string & # 160; Na Model STT: whisper (rhagosodedig), faster-whisper, sensevoice
language string & # 160; Na Côd iaith. auto ar gyfer darganfod yn awtomatig (rhagosodedig).
timestamps boolean & # 160; Na Cynnwys stampiau amser lefel gair. Rhagosodedig: false
diarize boolean & # 160; Na Galluogi diareiddio siaradwyr. Rhagosodedig: false

Ymateb

Ymateb JSON
{
  "text": "Hello, this is a transcription test.",
  "language": "en",
  "duration": 3.5,
  "segments": [
    {
      "start": 0.0,
      "end": 1.8,
      "text": "Hello, this is",
      "speaker": "SPEAKER_00"
    },
    {
      "start": 1.8,
      "end": 3.5,
      "text": "a transcription test.",
      "speaker": "SPEAKER_00"
    }
  ]
}

Clonio Llywio

POST /v1/tts/clone/

Creu siarad mewn llais clônedig. Lawrlwytho sain a testun cyfeirio.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
reference_audio file & # 160; IeQShortcut Sain llais cyfeirio (argymhellir 10-30 eiliad). Uchafswm 20MB.
text string & # 160; IeQShortcut Testun i'w ddweud yn y llais clonedig.
model string & # 160; Na Model clôn: chatterbox (rhagosodedig), cosyvoice2, gpt-sovits
format string & # 160; Na Fformat allbwn: mp3 (rhagosodedig), wav, flac
language string & # 160; Na Côd iaith cyrchfan. Rhaid ei gynnal gan y model a ddewiswyd.

Ymateb

Dychwelyd y ffeil sain fel data deuaidd, yr un fath â' r pwynt diwedd TTS.

Newidydd LlygaidName

POST /v1/voice-convert/

Trosi sain i swnio fel llais gwahanol. Lanlwytho'r sain ffynhonnell a dewis llais cyrchfan.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file & # 160; IeQShortcut Ffeil sain ffynhonnell (MP3, WAV, FLAC). Uchafswm 50MB.
target_voice string & # 160; IeQShortcut Dynodiad llais targed i'w drosi i (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael)
model string & # 160; Na Model trawsnewid llais: openvoice (rhagosodedig), knn-vc
format string & # 160; Na Fformat allbwn: wav (rhagosodedig), mp3, flac

Cais Enghreifftiol

cURL
curl -X POST https://api.tts.ai/v1/voice-convert/ \
  -H "Authorization: Bearer sk-tts-your-key" \
  -F "file=@source_audio.mp3" \
  -F "target_voice=af_bella" \
  -F "model=openvoice" \
  -o converted.wav

Ymateb

Dychwelyd y ffeil sain drosiedig fel data deuaidd.

Cyfieithiad LleferyddName

POST /v1/speech-translate/

Cyfieithu sain a lefarwyd o un iaith i'r llall. Cyfuno siarad-i-destun, cyfieithu, a testun-i-ganu mewn galwad sengl.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file & # 160; IeQShortcut Ffeil sain ffynhonnell yn yr iaith wreiddiol. Uchafswm 100MB.
target_language string & # 160; IeQShortcut Côd iaith cyrchfan (e.e. es, fr, de, ja)
voice string & # 160; Na Y llais ar gyfer yr allbwn cyfieithiad. Dewisir yn ymysgogol os anwybyddir.
preserve_voice boolean & # 160; Na Ceisio cadw'r siaradwr gwreiddiol

Ymateb

Ymateb JSON
{
  "original_text": "Hello, how are you?",
  "translated_text": "Hola, como estas?",
  "source_language": "en",
  "target_language": "es",
  "audio_url": "https://api.tts.ai/v1/results/translate_abc123.mp3",
  "credits_used": 5
}

Llafar- i- LafarComment

POST /v1/speech-to-speech/

Trawsnewid arddull siarad, teimlad, neu gyflwyno tra'n cadw'r cynnwys. Defnyddiol ar gyfer addasu ton, cyflymder, a mynegiant.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file & # 160; IeQShortcut Ffeil sain siarad ffynhonnell. Uchafswm 50MB.
voice string & # 160; IeQShortcut Dynodiad llais targed ar gyfer y siarad allbwn
model string & # 160; Na Model: openvoice (rhagosodedig), chatterbox
emotion string & # 160; Na Targed teimlad: neutral, happy, sad, angry, excited
speed float & # 160; Na Addasiad cyflymder. Rhagosodedig: 1.0. Amrediad: 0.5 i 2.0

Ymateb

Dychwelyd y ffeil sain trawsnewidedig fel data deuaidd.

Erfyn Sain

Gorffennodau prosesio sain ar gyfer gwella, tynnu llais, rhannu gwreiddiau, a mwy.

POST /v1/audio/enhance/

Uwchraddio ansawdd sain: dileu sŵn, uwchraddio clirwch, uwch-ddealltwriaeth.

file fileFfeil sain i'w gwella
denoise booleanGalluogi dileu sŵn (rhagosodedig: gwir)
enhance_clarity booleanCynyddu clirder siarad (rhagosodedig: gwir)
super_resolution booleanUwchraddio ansawdd sain (rhagosodedig: ffug)
strength integer1- 3 (ysgafn, canolig, cryf). Rhagosodedig: 2
POST /v1/audio/separate/

Gwahanu cerddoriaeth gerddorol o gerddoriaeth offerynnol (dileu cerddoriaeth gerddorol) neu rannu'r cerddoriaeth yn ddarnau.

file fileFfeil sain i'w gwahanu
model stringdemucs (rhagosodedig) neu spleeter
stems integerNifer o ddarnau: 2, 4, 5, neu 6 (rhagosodedig: 2)
format stringFformat allbwn: wav, mp3, flac
POST /v1/audio/dereverb/

Gwaredu adlewyrchiad o recordiadau sain.

file fileFfeil sain i'w phrosesu
type stringecho or reverb (default: both)
intensity integer1-5 (default: 3)
POST /v1/audio/analyze/ Rhydd

Dadansoddi sain i ganfod bysell, BPM, a llofnod amser.

file fileFfeil sain i'w dadansoddi
Ymateb
{
  "key": "C",
  "scale": "Major",
  "bpm": 120.0,
  "time_signature": "4/4",
  "camelot": "8B",
  "compatible_keys": ["C Major", "G Major", "F Major", "A Minor"]
}
POST /v1/audio/convert/ Rhydd

Trosi sain rhwng fformatau.

file fileFfeil sain i drosi
format stringFformat cyrchfan: mp3, wav, flac, ogg, m4a, aac
bitrate integerCyfradd did allbwn mewn kbps: 64, 128, 192, 256, 320
sample_rate integerCyfradd samplu: 22050, 44100, 48000
channels stringmono neu stereo

Sgwrs LaisName

POST /v1/voice-chat/

Anfon sain neu destun a derbyn ymateb AI gydag iaith synthetig.

Corff y Cais (multipart/form-data neu JSON)

ParamedrauMathAngenrheidiolDisgrifiad
audio file & # 160; Na* Mewnbwn sain (neu audio neu text angenrheidiol)
text string & # 160; Na* Mewnbwn testun (neu audio neu text angenrheidiol)
voice string & # 160; Na Llais ar gyfer ymateb AI. Rhagosodedig: af_bella
tts_model string & # 160; Na Model TTS ar gyfer ymateb. Rhagosodedig: kokoro
system_prompt string & # 160; Na Ymholiad cysawd addasiedig ar gyfer y AI
conversation_id string & # 160; Na Parhau sgwrs sy'n bodoli eisoes

Ymateb

Ymateb JSON
{
  "conversation_id": "conv_abc123",
  "user_text": "What is the capital of France?",
  "ai_text": "The capital of France is Paris.",
  "audio_url": "https://api.tts.ai/v1/audio/tmp/resp_xyz.mp3",
  "credits_used": 3
}

Batch TTS

POST /v1/tts/batch/

Cyflwyno testunau lluosol ar gyfer creu TTS paralel. Derbyn ad- alwad webhook os dymunwch pan fydd pob swydd wedi' i chwblhau.

Paramedrau

ParamedrauMathDisgrifiad
textsarrayArray of objects: {text, model, voice}. Max 50 items.
webhook_urlstringURL dewisol i'w ddefnyddio i POST canlyniadau pan mae'r batch yn gorffen.

Ymateb

Ymateb JSON
{
  "batch_id": "abc123",
  "total": 3,
  "completed": 0,
  "status": "processing"
}

Cynnydd pleidlais gyda GET /v1/tts/batch/result/?batch_id=abc123

Mewnosod Llywio

POST /v1/voice-embed/

Rhag-gyfrifo mewnosod llais o sain cyfeirio. Defnyddio'r embed_id a ddychwelir mewn ceisiadau clonio llais dilynol er mwyn creu'n syth.

Paramedrau

ParamedrauMathDisgrifiad
filefileReference audio file (WAV, MP3, FLAC).
modelstringCloning model (default: chatterbox). Supported: chatterbox, cosyvoice2, openvoice, gpt-sovits, spark, indextts2, qwen3-tts.

Ymateb

Ymateb JSON
{
  "embed_id": "emb_abc123",
  "model": "chatterbox",
  "duration_ms": 450
}

Gwirio Cyflwr

GET /v1/health/

Gwirio cyflwr y gweinydd GPU, modelau wedi'u llwytho, a maint y ciw. Dim angen dilysiant. Wedi'i gelc am 30 eiliad.

Ymateb

Ymateb JSON
{
  "status": "online",
  "latency_ms": 45,
  "queue_size": 3,
  "models_loaded": ["kokoro", "chatterbox", "cosyvoice2"]
}

Modelau Rhestr

GET /v1/models/

Dychwelyd rhestr o bob model sydd ar gael gyda' u galluoedd.

Ymateb

Ymateb JSON
{
  "models": [
    {
      "id": "kokoro",
      "name": "Kokoro",
      "type": "tts",
      "tier": "standard",
      "languages": ["en", "ja", "ko", "zh", "fr"],
      "supports_cloning": false,
      "supports_streaming": true,
      "credits_per_1k_chars": 2
    },
    {
      "id": "chatterbox",
      "name": "Chatterbox",
      "type": "tts",
      "tier": "premium",
      "languages": ["en"],
      "supports_cloning": true,
      "supports_streaming": true,
      "credits_per_1k_chars": 4
    }
  ]
}

Rhestr Gerddoriaeth

GET /v1/voices/

Dychwelyd rhestr o' r holl lais sydd ar gael, wedi' u hidlo yn ôl model neu iaith os dymunwch.

Paramedrau Ymholiad

ParamedrauMathDisgrifiad
model string Hidlo yn ôl ID model (e.e. kokoro)
language string Hidlo yn ôl cod iaith (e.e. en)
gender string Hidlo yn ôl rhyw: gwrywaidd, benywaidd, cydnaws

Ymateb

Ymateb JSON
{
  "voices": [
    {
      "id": "af_bella",
      "name": "Bella",
      "model": "kokoro",
      "language": "en",
      "gender": "female",
      "preview_url": "https://api.tts.ai/v1/voices/preview/af_bella.mp3"
    }
  ],
  "total": 142
}

Isdeitlau (SRT / VTT) newydd

GET /v1/speech/subtitles/?uuid=<job_uuid>&format=srt|vtt&download=1

Creu isdeitlau cydweddol ar gyfer unrhyw waith TTS wedi'i gwblhau. Rhedeg alinio chwiban dros y sain a dychwelyd SRT neu WebVTT. Cedwir y canlyniad ar ddisg fel bod ail alwad ar gyfer yr un uuid yn darlleniad disg.

Paramedrau Ymholiad

ParamedrauAngenrheidiolDisgrifiad
uuid& # 160; IeQShortcutDychwelwyd yr UUID swydd gan /v1/tts/ neu /v1/voice-clone/.
format& # 160; Nasrt (rhagosodedig) neu vtt.
download& # 160; Na1 i anfon Content-Disposition: attachment fel bod y porwr yn cadw yn hytrach na dangos.
language& # 160; NaCynghoryn i'r model alinio (yn cael ei ganfod yn awtomatig os ei ohirio).
cURL
curl "https://api.tts.ai/v1/speech/subtitles/?uuid=$UUID&format=srt&download=1" -o subtitles.srt

Geiriadur Ynganiad newydd

GET POST DELETE /api/v1/pronunciations/

Dywedwch wrth y peiriant TTS sut i alw geiriau penodol. Caiff cofnodion wedi'u cadw eu defnyddio'n awtomatig ar bob cais TTS rydych yn ei wneud. Terfyn o 200 cofnod ar gyfer pob cyfrif.

Corff y Cais (POST)

ParamedrauMathDisgrifiad
wordstringY gair i'w drosysgrifo (e.e. GIF, Anthropic). Cydweddodd ffiniau geiriau.
replacementstringSut i'w sillafu ar gyfer y model (e.e. jiff, ann THROP ick).
languagestringCôd ISO dewisol. Gwag = yn berthnasol i bob iaith.
case_sensitivebooleanfalse rhagosodedig. Cydweddu llythrennau bach a mawr yn union pan fo true.
cURL
# Save an entry
curl -X POST https://tts.ai/api/v1/pronunciations/ \
  -H "Authorization: Bearer sk-tts-..." \
  -H "Content-Type: application/json" \
  -d '{"word": "GIF", "replacement": "jiff"}'

# List your entries
curl https://tts.ai/api/v1/pronunciations/ -H "Authorization: Bearer sk-tts-..."

# Delete entry by id
curl -X DELETE "https://tts.ai/api/v1/pronunciations/?id=42" -H "Authorization: Bearer sk-tts-..."

Gallwch hefyd basio trosglwyddiadau ar gyfer pob cais heb eu cadw — gan gynnwys pronunciations ar unrhyw alwad /v1/tts/ fel naill ai gwrthrych neu array (gweler y paramedrau diwedd TTS).

Erthygl newydd

Rhowch tag